There are hundreds of Git commands available to use for one reason or another. However, in this article, you will find the top 20 most used Git commands, along with a short description and an example of usage for each.
If you would like to view all other Git command examples you can see them all by going here.
*Please Note: These Git commands are in no particular order.
Top 20 Git Commands
This sets the configuration values for your username, email, gpg key, preferred diff algorithm, file formats and more:
This initializes a git repository, and creates the initial .git directory in a new or already existing project:
This command creates a Git repository copy from a remote source. The command will also add the original location as a remote location so you are able to fetch from it again and push to it if you have permissions:
This will add file changes that are in your working directory to your index:
This will remove files from your index and your working directory so they will not be tracked:
This Git command takes all of the changes written in the index, creates a new commit object pointing to it, and sets the branch to point to that new commit:
This Git command shows the status of files in the index versus the working directory. It will list out files that are untracked (only in your working directory), modified (tracked but not yet updated in your index), and staged (added to your index and ready for committing):
This lists existing branches, including remote branches if ‘-a’ is provided. It will create a new branch if a branch name is provided:
This will merge one or more branches into your current branch. It also automatically creates a new commit if there are no conflicts:
This command will reset your index and working directory to the state of your last commit. Effectively taking you back:
This Git command tags a specific commit with a simple, human readable handle that never moves:
This will fetch all the files from the remote repository and merge them with your local one:
This Git command will push all the modified local objects to the remote repository and advances its branches:
This shows all the remote versions of your repository:
This command will show a list of commits on a branch, and include the corresponding details:
This command will generate patch files or statistics of differences between paths or files in your git repository, index, or your working directory:
This command will create a tar or zip file that includes the contents of a single tree from your repository:
This is a garbage collector Git command. It will collect garbage from your repository and optimize the repository as well. You should run this periodically:
This will perform an integrity check of the Git file system and identify corrupted objects:
This Git command will remove objects that are no longer pointed to by any object in any reachable branch. Like pruning a tree of useless branches:
Understanding how to use Git commands is important if you are going to be using Git a lot. Hopefully some if these more popular Git commands are easy to use and understand.
Author: Jeremy Holcombe
Growing up in Hawaii, Jeremy started his freelance writing career doing resumes, business plans, article writing, and everything in between. He now specializes in online marketing and content writing and is part of the Content Marketing Team at GreenGeeks.