Skip to content

Learn

10 common Git commands everyone should know

 

Common Git command used

Version control (sometimes referred to as source control) plays an important role in any development project, including test automation. It is the practice of tracking and providing control over changes made in the source code. Git is one of the most common version control systems (VCS). Let’s walk through some of the most common Git commands.

What are Git commands?

Git is a fast, scalable, and distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals. Git commands were originally designed for coordinating work among programmers who were operating source codes during software development.

Benefits of Git

  • It’s free and open-source
  • Performance is faster and more reliable than any other version control software, as it focuses on file content rather than on file names.
  • Git provides security by protecting the code and the change history through a cryptographically secure hashing algorithm called SHA1.
  • Git has become the preferred VCS tool in many top organizations.

Most common Git commands

Using git help in the command prompt (on Windows), terminal (for Mac), or shell (on Linux) will give you a list of available Git commands:

Git help commands list

Let’s look over some of the most useful Git commands.

1. git clone

Use this command for downloading the latest version of a remote project and copying it to the selected location on the local machine. It looks like this:

git clone <repository url>

Here’s an example:

Git clone commands

To clone a specific branch, you can use

git clone <repository url> -b <branch name>

2. git fetch

Use this Git command to get all the updates from the remote repository, including new branches.

3. git checkout

Use the checkout command to switch the branch that you are currently working on.

git checkout <branch name>

Create a new branch and switch to it by using this command:

git checkout -b <branch name>

4. git init

Start a new empty repository or to reinitialize an existing one in the project root. It will create a .git directory with its subdirectories. It should look like this:

git init <repository name>

5. git commit

This is probably the most used Git command. After changes are made locally, save them by “committing” them. A commit is like a local snapshot of the current state of the branch, to which you can always return. To create a new commit, type this command in Git Bash:

git commit -m “<commit message>”

If all goes well, you will see the changes in the commit:

Git commit commands

6. git push

Git push will push the locally committed changes to the remote branch. If the branch is already remotely tracked, simply use it like this (with no parameters):

git push

If the branch is not yet tracked, and only resides on the local machine, run the command like this:

git push –set-upstream <remote branch> <branch name>

Git push commands

7. git diff

Use this command to see the unstaged changes on the current branch. Here’s an example of a branch with an edited feature file:

Git diff

If you want to see the staged changes, run the diff command like this:

git diff –staged

Or compare two branches:

gif diff <branch1> <branch2>

8. git pull

Use git pull to fetch all the changes from the remote repository and merge any remote changes in the current local branch.

9. git add

Use this command to stage changed files. You can stage individual files:

git add <file path>

or all files:

git add .

10. git branch

Use git branch to list all the branches of the repository:

Git branch

Or you can use it to create a new branch, without checking it out:

git branch <new branch>

To delete a branch, run it like this:

git branch -d <branch name>

Conclusions

Git can be a really powerful tool in any development project. If your team uses Git for version control, you will probably use most of these commands daily.

About the author

Andreea Draniceanu

Andreea is a QA engineer, experienced in web and desktop applications, and always looking to improve her automation skills and knowledge. Her current focus is automation testing with C#.

Author:

Guest Contributors

Date: Aug. 22, 2025
Author:

Guest Contributors

Date: Aug. 22, 2025

You may also be interested in...