Basic GIT Commands


When it comes to version control systems, there are very few out there that can outshine GIT in relevance, performance and prevalence. GIT was developed by Linus Torvalds in 2005 and today, millions of companies use it for efficient code management and version control of their projects. The open-source software can be downloaded for Linux, Windows, Solaris and Mac platforms; more information about GIT basics can be retrieved here. In this tutorial, the most basic git commands will be talked about.

What you’ll need

Before you begin this guide, you’ll need the following:

  • GIT installed on your system

Basic GIT Commands

  • git config
    One of the most used git commands is git config which can be used to set user-specific configuration values like email, preferred algorithm for diff, username and file format etc. For example, the following command can be used to set the email:
  • git init
    This command is used to create a new GIT repository. Usage:
  • git add
    The git add command can be used in order to add files to the index. For example, the following command will add a file named temp.txt present in the local directory to the index:
  • git clone
    The git clone command is used for repository checking out purposes.
    If the repository lies on a remote server, use:
    Conversely, if a working copy of a local repository is to be created, use:
  • git commit
    The git commit command is used to commit the changes to the head. Note that any committed changes won’t make their way to the remote repository. Usage:
  • git status
    The git status command displays the list of changed files along with the files that are yet to be added or committed. Usage:
  • git push
    git push is another one of the most used basic git commands. A simple push sends the made changes to the master branch of the remote repository associated with the working directory. For example:
  • git checkout
    The git checkout command can be used to create branches or to switch between them. For example, the following creates a new branch and switches to it:
    To simply switch from one branch to another use:
  • git remote
    The git remote command lets a user connect to a remote repository. The following command lists the remote repositories that are currently configured:
    This command allows the user to connect the local repository to a remote server:
  • git branch
    The git branch command can be used to list, create or delete branches. To list all the branches present in the repository use:
    To delete a branch:
  • git pull
    In order to merge all the changes present on the remote repository to the local working directory, the pull command is used. Usage:
  • git merge
    The git merge command is used to merge a branch into the active branch. Usage:
  • git diff
    The git diff command is used to list down conflicts. In order to view conflicts with the base file, use
    The following command is used to view the conflicts between about-to-be-merged branches prior to merging them:
    To simply list down all the present conflicts, use:
  • git tag
    Tagging is used to mark specific commits with simple handles. An example can be:
  • git log
    Running the git log command outputs a list of commits on a branch along with pertinent details. A sample output can be:
  • git reset
    To reset the index and the working directory to the last commit’s state, git reset command is used. Usage:
  • git rm
    git rm can be used to remove files from the index and the working directory. Usage:
  • git stash
    Probably one of the lesser-known basic git commands is git stash which helps in saving changes that are not to be committed immediately, but on a temporary basis. Usage:
  • git show
    In order to view information about any git object, use the git show command. For example:
  • git fetch
    git fetch allows a user to fetch all those objects from the remote repository that doesn’t currently reside in the local working directory. Example usage:
  • git ls-tree
    To view a tree object along with the name and mode of each item, and the blob’s SHA-1 value, use the git ls-tree command. For example:
  • git cat-file
    Using the SHA-1 value, view the type of an object by using the git cat-file command. For example:
  • git grep
    git grep lets a user search through the content trees for phrases and/or words. For example, to search for in all files use:
  • gitk
    gitk is the graphical interface for a local repository that can be invoked by typing and running:
  • git instaweb
    With the git instaweb command, a web server can be run interfaced with the local repository. A web browser is also automatically directed to it. For instance:
  • git gc
    To optimize the repository via garbage collection, which will cleanup unneeded files and optimize them, use:
  • git archive
    The git archive command lets a user create a zip or a tar file containing the constituents of a single repository tree. For instance:
  • git prune
    Via the git prune command, objects that don’t have any incoming pointers are deleted. Usage:
  • git fsck
    In order to perform an integrity check of the git file system, use the command git fsck. Any corrupted objects are identified:
  • git rebase
    The git rebase command is used for reapplication of commits on another branch. For instance:

GIT Cheat Sheet in .pdf

We understand that it can be hard to remember even basic GIT commands. Especially if you are just starting with GIT.

That’s why we put together a GIT cheat sheet which contains the most used GIT commands.

Download (size:1.2MB)


Aforementioned were some of the frequently used basic git commands. Be sure to checkout our GIT tutorial for an easy-to-follow instruction on how to setup and use GIT.

Add Comment

Click here to post a comment

Join thousands of subscribers worldwide

and get awesome deals & the newest tutorials to your email

Please wait...

Thank you for sign up!

More in GIT
GIT Basics Tutorial – Getting Started with GIT