Basic Git Commands for Beginners - A Step-by-Step Guide
Shamal Lakshan

If you’re new to the world of version control and collaborative coding, Git is an essential tool to learn. Git allows developers to track changes in their code, collaborate with others, and smoothly manage project versions. With a little practice, you’ll find that Git can greatly streamline your development process. In this blog post, we’ll walk you through some basic Git commands that every beginner should know.

  1. Setting Up Git

Before we dive into the commands, make sure you have Git installed on your computer. You can download and install Git from the official website here. Once it’s installed, open a terminal or command prompt and set up your Git username and email using the following commands:

1
2
$ git config --global user.name "Your Name"
$ git config --global user.email "your_email@example.com"
  1. Creating a New Repository

To start using Git for a new project, you need to initialize a new Git repository. Navigate to the root directory of your project and run the following command to create a new repository:

1
$ git init
  1. Adding and Committing Changes

After making changes to your files, you need to tell Git which changes to include in the next commit. To add all the changes, use the following command:

1
$ git add .

This command stages all the changes in the current directory for the next commit. Once your changes are staged, you can commit them using:

1
$ git commit -m "Your commit message here"
  1. Checking the Status and History

To see which files are staged, unstaged, or untracked, use the following command:

1
$ git status

If you want to see a history of commits, including commit messages, dates, and authors, use:

1
$ git log
  1. Working with Branches

Git allows you to work on different features or versions of your project simultaneously by using branches. To create a new branch, use:

1
$ git branch 

To switch to a different branch, use:

1
$ git checkout 
  1. Merging Changes

Once you’ve made changes in a separate branch and want to incorporate those changes back into the main branch, you can merge the branches together. First, switch to the branch where you want to merge the changes (e.g., the main branch) and then run:

1
$ git merge 
  1. Cloning a Repository

If you want to work on a project that already exists in a remote repository, you can clone it to your local machine using:

1
$ git clone 

These are just a few of the many Git commands available, but they represent a solid foundation for using Git in your day-to-day development work. As you become more comfortable with Git, you’ll find there are many other powerful commands and workflows to explore. Remember, practice makes perfect, so don’t be afraid to experiment and learn as you go.

Happy cod7ing!