GIT Commands Tutorial

Learn what are and how to use the most common GIT commands

This tutorial provides a list of the most common GIT commands, a short description for them and example usage. For a detailed description of all the GIT commands please check this page.

  • git config

Sets configuration values for your user name, email, gpg key, preferred diff algorithm, file formats and more. Examples:

  • git init

Initializes a git repository – creates the initial .git directory in a new or in an existing project. Example:

  • git clone

Creates a GIT repository copy from a remote source. Also adds the original location as a remote so you can fetch from it again and push to it if you have permissions. Example:

  • git add

Adds files changes in your working directory to your index. Example:

  • git rm

Removes files from your index and your working directory so they will not be tracked. Example:

  • git commit

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. Examples:

  • git status

Shows you 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). Example:

  • git branch

Lists existing branches, including remote branches if ‘-a’ is provided. Creates a new branch if a branch name is provided. Example:

  • git merge

Merges one or more branches into your current branch and automatically creates a new commit if there are no conflicts. Example:

  • git reset

Resets your index and working directory to the state of your last commit. Example:

  • git tag

Tags a specific commit with a simple, human readable handle that never moves. Example:

  • git pull

Fetches the files from the remote repository and merges it with your local one. Example:

  • git push

Pushes all the modified local objects to the remote repository and advances its branches. Example:

  • git remote

Shows all the remote versions of your repository. Example:

  • git log

Shows a listing of commits on a branch including the corresponding details. Example:

  • git diff

Generates patch files or statistics of differences between paths or files in your git repository, or your index or your working directory. Example:

  • git archive

Creates a tar or zip file including the contents of a single tree from your repository. Example:

  • git gc

Garbage collector for your repository. Optimizes your repository. Should be run occasionally. Example:

  • git fsck

Does an integrity check of the Git file system, identifying corrupted objects. Example:

  • git prune

Removes objects that are no longer pointed to by any object in any reachable branch. Example: