Git cheatsheet
Quick reference for Git commands and workflows
Git Cheatsheet
Common Git commands with descriptions
Configuration
git config --global user.name "Name"git config --global user.email "email"git config --listRepository
git initgit clone <url>git statusBasic
git add .git add <file>git commit -m "message"git commit --amendgit diffgit diff --stagedBranching
git branchgit branch <name>git checkout <branch>git checkout -b <name>git merge <branch>git rebase <branch>git branch -d <name>Remote
git remote -vgit remote add origin <url>git fetch origingit pull origin <branch>git push origin <branch>git push -u origin <branch>History
git loggit log --onelinegit log --graph --onelinegit blame <file>Undoing
git reset HEAD <file>git checkout -- <file>git revert <commit>git reset --hard HEAD~1Stashing
git stashgit stash popgit stash listgit stash dropTags
git tag <name>git tag -a <name> -m "msg"git push origin --tagsTL;DR
What is Git cheatsheet?
Git is a distributed version control system created by Linus Torvalds in 2005. It tracks changes to files over time, allowing multiple developers to collaborate on the same codebase, branch independently, and merge changes. This cheatsheet covers the most-used commands organized by workflow stage.
Common use cases
- ‣Daily workflow: look up the exact syntax for staging, committing, branching, and merging
- ‣Onboarding: reference for developers new to Git who need to connect command names to their purpose
- ‣Recovery: find the right command to undo a change, reset a branch, or recover a deleted commit
Frequently asked questions
What is the difference between git pull and git fetch?
git fetch downloads new commits and branches from the remote but does not change your working directory or current branch. git pull is a shorthand for git fetch followed by git merge (or rebase). Use git fetch when you want to see what changed before integrating.
What is the difference between git reset and git revert?
git reset moves the branch pointer backward, effectively removing commits from history (use with caution on shared branches). git revert creates a new commit that undoes the changes of a previous commit without rewriting history. Use git revert on shared branches; use git reset only on local commits.