Git Cheat Sheet

This cheat sheet contains all commonly used commands, while you work with git. But, it is difficult to keep remember all these commands and you prepare stickies to make these noted down. But now, no more stickies of Git. You can use this cheat sheet as your sticky notes. 

Init & Clone Setup config
  • Make an existing directory into a Git Repository
    git init
  • Get a clone repository located at give URL onto your local machine.
    git clone URL
  • Set name that will be allies when you commit the changes and visible in transaction history. So, other team members will know who commit the changes.
    git config --global user.name <name>
  • Set an email address that will be associated with each history marker
    git config --global user.email <email-address>
Branch & Checkout
  • List all branches in your repo. A star (*) will show next to the active branch.
    git branch
  • Create new branch
    git branch <branch-name>
  • Switch to another existing branch (It will throw an error if branch doesn't exists.)
    git checkout <branch-name>
  • Create new branch and switch to it (This command will not throw an error if branch doen't exists. This command is the combination of git branch + git checkout commands)
    git checkout <branch-name>
  • Delete branch
    git branch -d <branch-name>
Pull and Push
  • Downloads all history from the remote tracking branches. But will not merge with you local branch.
    git fetch
  • Downloads all history from specific remote tracking branch.
    git fetch <branch-name>
  • Combines specific remote tracking branch into current local branch
    git merge <branch-name>
  • Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. It is combination of git fetch and git merge commands
    git pull <branch-name>
  • Upload your local commits in given remote branch.
    git push <branch-name>
Commit and Staging
  • Commit your staged content as a new commit snapshot
    git commit -m "<commit-message>"
  • Add newly added specific file in stage so that it will appear in versioning.
    git add <file-name>
  • Add all new added files in staging. Don't miss dot (.)
    git add .
  • Show list of modified files in working directory an staged, unstaged and untrack chanages
    git status
Difference UNDO changes
  • Shows what are the changes in specific files.
    git diff "<file-name>"
  • Shows what are the changes, one by one in all file.
    git diff
  • Discard changes for specific file
    git checkout -- "<file-name>"
  • Discard all local changes
    git reset --hard HEAD

Comments