20+ Git Commands Extensive list - ByteScout
  • Home
  • /
  • Blog
  • /
  • 20+ Git Commands Extensive list

20+ Git Commands Extensive list

Git is an open-source distributed variant system tool created to manage various projects with agility and adaptability. It was designed by Linus Torvalds in the year 2005 to improve Linux Kernel. Git has the functionality, administration, defense, and docility that most people need. You may now use Git with services like GitHub and Gitlab for creating free Git-based repositories with your code inside and then tracking all the changes.

Technical SEO

The following is the list of important Git commands:

  1. git config – configs default settings for Git like your name and email that will be stored in Git and will be attached to changes you have made.
  2. git init – initializes new empty repository in the folder and starts tracking changes
  3. git add – adds new file (or files by mask) to be tracked for the current set of changes
  4. git clone – clones existing git repository from URL. With this command, you can download and copy the existing project from Github, Gitlab, or any other Git hosting
  5. git commit – saves the current set of changes (including ones you have added with “git add”) into the local history
  6. git status – shows the list of files in the current set of changes and indicates their current status (per file)
  7. git diff – shows exact changes that were made in the new version of the file vs the old version of the file
  8. git branch – creates a new “branch” with the current set of files. This is useful if you want to try something but not in the main “master” branch
  9. git merge – merges changes
  10. git reset – resets currently made changes
  11. git rm – removes file or files from changes
  12. git checkout – restores files or files to the state how they were last time synced from remote Git
  13. git pull – pulls new changes from remote Git repository
  14. git push – sends new changes to the remote Git repository
  15. git remote – displays. the list of remote Git repositories set for the current repository
  16. git log – shows the list of changes made in the local history
  17. git archive – creates a ZIP archive from files in the current repository
  18. git gc – optimizes current git repository
  19. git fsck – checks the integrity of the current git repository
  20. git stash – saves altered files
  21. git prune – removes “lost” objects
  22. git clean – remove new files that were added into the repository but not tracked yet

1. git config

This command is one of the first git commands you should run after installing Git on your computer. It is used to configure your personal. profile and things such as username, email, domain, and much more. The following example is displaying the use of git config to set the username and its email.

git config –global user.name “jeff”
git config –global user.email “jeff@example.com”

2. git init

This is one of the git basic commands that you should use for a new Git repository. It starts a git repository and formulates the initial .git directory in a new or previously created project. For example, the following command initializes the empty Git repository.

git init
Initialized empty Git repository in /home/myfolder/GITFOLDER/.git/

3. git add

This command is one of the most used git commands. This command adds a file or files in the indexed working directory. For example, the following command is adding project1 in the indexed working directory.

git add project1

git add *.js – adds all *.js files in the current folder into tracking for changes in the Git repository

4. git clone

This command is the most widely used git command in the git commands list because you can use it to automatically download remote Git repository into your computer. It generates a copy of the Git repository from an old source. The command will also attach the primary spot as a detached location so users are capable to retrieve from it again and push. For example,

git clone git@github.com:jeff/mydir.git

git clone http://git@github.com:bytescout/ByteScout-SDK-SourceCode.git – this will download and save ByteScout samples Git repository into “ByteScout-SDK-SourceCode” folder

5. git commit

The “commit” in git commit is applied to save the changes to the git repository. It takes all of the modifications addressed in the index, generates a fresh commit object aiming at it, and inserts the git branch to the new commit. For, example, the following command is using git commit.

git commit -m ‘saving all the changes’
git commit -a -m ‘saving all changes, similar to git add and git commit’

6. git status

This Git command displays the status of records in the index against the functioning directory. It displays files that are not tracked, altered, tracked but not updated, and already in the queue for committing. The following example will display status.

git status


# On branch master #
# Initial commit #
# Untracked files: #

7. git diff

This command displays the file discrepancies. In other words, this command displays the differences which are still not staged. With the help of this command, the differences between the two branches can also be displayed. The git branch is just a movable pointer.  For example,

git diff

8. git branch

This is the most significant command for git list branches. It displays current branches, such as distant branches if extension ‘-a’ is mentioned. It can also produce a new git push branch if a branch name is given: For example

git branch -a * master remote1/source/master

9. git merge

This is one of the common git commands. As the name suggests, it can merge one or more git branches into your existing branch. It also implicitly forms a new commit if there are no disputes. The git merge command allows to use of the self-governing lines of development produced by the git branch and combines them into a separate branch. It is important to note that all of the commands merge into the existing branch. For example, the following command is displaying the use of the merge command.

git merge mybranch_2

10. git reset

The git reset is one of the useful git commands. This command resets the index and current working directory to the condition of your last commit. This is just like a rollback but up to the last commit. The git reset is an important command that is utilized to undo local modifications to the nature of a Git repository. Git reset works on the three trees. These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory.

For example, the following command resets the myfile.css up to the last commit.

git reset myfile.css

11. git rm

This is one of the most useful git cmd commands. This command is used to delete the file from the current directory and stages the removal. For example, the following command removes the testfile.txt from the current directory.

git rm testfile.txt

git rm *.log – removes all *.log files from tracking


12. git checkout

This is one of the most important gits command-line tools. The checkout command is used to switch from one git branch to another. For example, the following command is displaying the use of the checkout command to switch to branch_3

git checkout branch_3

13. git pull

The git pull request is one of the most used git commands. It retrieves and merges variations on the distant server to the current working directory. For example, the following command is displaying how to retrieve the variations on a remote server.

git pull http://git@github.com:bytescout/ByteScout-SDK-SourceCode.git

14. git push

The git push command is one of the most important git commands. This command is used to push all the updated or remodeled bounded objects to the remote git repository and develop its git branches. For example, the following command is displaying the use of push.

git push origin: branch_3

15. git remote

This is one of the most useful git commands. It is used to display all the remote variants of the git repository. A remote repository in Git is a public repository that developers utilize to swap their changes. For example, the following command is displaying the effective use of the git remote command.

git remote origin

16. git log

The git log command is one of the most crucial commands. It is used to display all the commits on a git branch and display the analogous details. The Git Log command enables the user to observe data about earlier commits that have transpired in a project. The purest variant of the log command displays the commits that drive up to the status of the checked-out git branch. The following example is displaying the use of the git log command.

git log commit

17. git archive

The git archive is one of the common git commands. This command is used to create a zip file that involves the data of a private tree from the git repository. It also generates an archive of the defined setup comprising the tree structure for the selected tree and addresses it out to the conventional output. The following example is displaying the use of the git archive command.

git archive –format=zip master^ MYFILE >file.zip

18. git gc

This command is one of the top git commands. It works as a garbage collector. This command is used to collect garbage from the git repository. The great thing about this command is that it is also used to optimize the repository. It should be run periodically. The following example is displaying the use of git gc

git gc

After running the above command it produces the following result:

Counting objects: 11, done.
Delta compression using up to 5 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), done.
Total 11 (delta 1), reused 0 (delta 0)

19. git fsck

This command is one of the most crucial git commands. It is also known as a File System Check. The name is just like that of the Unix fsck command. It is also used to validate a file system. The git fsck command will conduct an integrity analysis of the Git file system and recognize infected objects. For example, the following command will perform the integrity analysis.

git fsck

20. git stash

The git stash command is one of the most useful git commands. This command is used to tentatively save all the altered traced files. In other words, stashing is responsible for taking the modified tracked files and staged modifications and saves them on a stack of incomplete developments that the user can apply at any time. The following example is displaying the use of git stash

git stash save

21. git prune

This command is one of the most useful git commands. It is used to eliminate objects that are no longer aimed at by any object in any branch. The git prune command is an in-house service that sweeps up orphaned objects. These objects are those that are difficult to access by any refs. Prune is recognized as a garbage accumulation command and is a subordinate command of the git gc. The following example is displaying the use of the git prune command.

git prune

22. git clean

This command is the command that helps to clean from non-tracked files in your Git repo. Sometimes if you have a lot of files generated during compilation or work of your application you may need to have a way to quickly remove them to avoid accidental addition of these files into the main Git repository/

git clean -n – will simulate the removal of all the untracked files in your repository

git clean -n "*.log" – will simulate removal of all the untracked *.log files

git clean -f "*.log" – will remove all the untracked *.log files from the current repository


The above git commands cheat sheet is crucial for any developer.  One of the most important benefits of Git is its branching abilities. Unlike centralized variant control networks, Git branches are standard and simple to merge. This helps the branch workflow successful with many Git users. Feature branches present a remote environment for each modification to the codebase.

The feature branch workflow also gives adaptability when preferences shift. For example, if you’re midway through a release period and you want to delay one characteristic instead of a different time-crucial one, it can also be done.


GIT Bash Commands

Bash commands for GIT Git Bash is a tool that provides an emulation layer for the Git command line interface for Microsoft Windows systems.

BASH stands for Bourne Again Shell, a shell or terminal program allowing written command-line access to an operating system. Bash is one of the most used default shells for Linux and macOS.

A program called Git Bash installs Bash along with a few standard bash functions for Windows. The /usr/bin directory of the Git Bash emulator contains additional commands that come with Git Bash.

On Windows, Git Bash may offer a reasonably feature-rich shell environment. The following shell commands not covered by this document are bundled with Git Bash: SCP, cat, and ssh.

Git Bash offers the entire collection of Git core commands covered throughout this website and the previously discussed Bash commands.

For more information on git clone, git commit, git checkout, git push, and other git operations, visit the relevant documentation pages.

GIT Bash Command Example

Git config -global user. The Name "[name]" is the syntax to use.
git config -global user.email "[email address]" is the syntax to use.

This command sets the author name and email address with each of your commits.

GIT Commands in Linux

This version control system, which is free and open-source, can effectively manage small to large projects. A source code change tracking tool called Git enables multiple engineers to work together on non-linear development. Git was developed in 2005 by Linus Torvalds for the Linux kernel. Get Linux set up with Git.

  • Use apt-get to install Git from your shell: Sudo apt-get update for $ Install Git with Sudo apt-get.
  • If you do the Git —version, you can confirm the installation was successful. Version 2.9.2 of git.
  • Set up your email and Git login using the scripts below. In place of Emma, use your name.

GIT Linux Command Example

Git config —global "Linuxtechi User" user.name
Git config —global "linuxtechiuser@linuxtechi.com" user.email

Commands for GIT on Windows

Commands in GIT You must launch a terminal on your computer to execute Git commands (also known as a command prompt, command shell, and command line).

Git is preconfigured as a command line option on Linux and macOS devices. A Git command is not present in Windows, though.

Windows Users Should

  • Integrated command line. Choose the search icon on the Windows taskbar, then type cmd.
  • GitHub Bash Git for Windows includes it by default.

GIT Terminal Commands

A group of command-line tools called Git was developed to function in a command-line environment resembling a Unix system.

Modern operating systems like Linux and macOS come with both integrated Unix command line terminals. B.602ecause of this, using Linux and macOS together when using Git is complimentary.

GitHub Shell Commands

This is an SSH login shell for restricted access to Git.

It only allows for executing server-side Git commands that implement the pull/push capability and any custom commands found in the user’s home directory’s git-shell-commands subdirectory.

Standard Git Commands

  • Git init launches a fresh Git repository and starts following an already-existing directory.
  • A project that already exists remotely is created locally through git clone.
  • Git adds changes are staged.
  • The change-tracking procedure is finished with a git commit, which saves the snapshot of the project’s history.

About the Author

ByteScout Team ByteScout Team of Writers ByteScout has a team of professional writers proficient in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.