Git cheat sheet

Git: distributed repository is the new centralize.

Common used git command. I keep it brief with no/minimum explanation of each command by hoping that those commands are self explanatory. I also organize by git trifecta of Add/Modify – Branch – Remote workflow.

Add, check and publish. The basic

  1. Starting
    • git init
    • git clone <repository-url>
  2. Adding/making changes
    • git add .
    • git add <path/>
    • git commit -am “”
  3. Checking status
    • git status
    • git log —-all —-graph —-oneline
    • git log branch1..branch2
  4. Getting updates
    • git fetch Fetches latest changes from origin
    • git pull Fetches latest changes from origin and merge
  5. Publishing
    • git push Push changes to origin from current
    • git push <origin> <branch> Push changes to origin from branch


Modify, fixing mistakes

  1. Revert commits
    • git revert HEAD
    • git revert <commit-ref>
  2. Revert/undo all changes
    • git checkout - <file>
  3. Fix last commits
    • git commit –amend [-m “updated message”]
  4. Reset modifications
    • git reset HEAD <file>
  5. Diff-erence
    • git diff
    • git diff $id1 $id2 Diff between 2 commits
  6. Resolving changes
    • git checkout –ours <path/file>
    • git checkout –theirs <path/file>
  7. Combine commits
    • git rebase -i HEAD~4



  1. Creating branch
    • git branch <branch name>
  2. Listing branch
    • git branch
    • git branch -a
    • git branch -v
  3. Switching branch
    • git checkout <branch-name>
    • git checkout -b <branch-name>
  4. Merging branch
    • git merge <branch-name>
    • git merge --squash <branch-name>
  5. Deleting branch
    • git branch -d <branch-name>



  1. Adding remote
    • git remote <remote-name> <remote-url>
  2. Listing remote
    • git remote -v
  3. Fetching/Pushing to/from remote
    • git fetch <remote-name>
    • git push <remote-name> <branch-name>
  4. Getting update without removing local
    • git stash
    • git pull
    • git stash pop


Also, use .gitignore file for ignore files or directories. For further reference for more detailed git usage, my go to is


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s