Git Cheatsheet
Essential Git commands for branching, merging, interactive rebasing, stash operations, reflog disaster recovery, and cherry-picking.
Setup & Config
5 commandsgit config --global user.name "<name>"beginnerSet the author name used on your commits
git config --global user.email "<email>"beginnerSet the author email used on your commits
git config --listbeginnerShow all current Git configuration values
git initbeginnerCreate a new empty Git repository in the current directory
git clone <url>beginnerCopy a remote repository to your machine
Staging & Committing
6 commandsgit statusbeginnerShow the working tree status - staged, unstaged and untracked files
git add <file>beginnerStage changes for the next commit
git commit -m "<message>"beginnerRecord staged changes to the repository history
git diffbeginnerShow changes between working tree and the index
git rm <file>intermediateRemove a file from the working tree and stage the deletion
git mv <src> <dest>beginnerMove or rename a file and stage the change
Branching
5 commandsgit branchbeginnerList all local branches (current marked with *)
git switch <branch>beginnerSwitch to an existing branch
git switch -c <branch>beginnerCreate a new branch and switch to it
git branch -d <branch>beginnerDelete a branch that has been merged
git branch -m <new-name>intermediateRename the current branch
Merging & Rebasing
4 commandsgit merge <branch>intermediateMerge another branch into the current branch
git rebase <branch>advancedReapply your commits on top of another branch for a linear history
git rebase -i HEAD~<n>advancedInteractively rewrite the last n commits
git cherry-pick <commit>advancedApply a specific commit from another branch
Remotes & Syncing
5 commandsgit remote -vbeginnerList configured remote repositories and their URLs
git remote add <name> <url>beginnerAdd a new remote repository
git fetch <remote>intermediateDownload objects and refs without merging
git pullbeginnerFetch from the remote and merge into the current branch
git pushbeginnerUpload local commits to the remote
Undoing Changes
6 commandsgit restore <file>beginnerDiscard uncommitted changes in a file
git reset <file>beginnerUnstage a file while keeping its changes
git reset --soft HEAD~1intermediateUndo the last commit but keep changes staged
git reset --hard <commit>advancedReset the branch and working tree to a commit, discarding changes
git revert <commit>intermediateCreate a new commit that undoes a previous commit
git reflogadvancedShow a log of where HEAD has been - your safety net
Stashing
5 commandsgit stashintermediateSave uncommitted changes and revert to a clean tree
git stash listbeginnerList all stashed change sets
git stash popintermediateApply the most recent stash and remove it from the list
git stash applyintermediateApply a stash but keep it in the stash list
git stash dropintermediateDelete a specific stash
History & Inspection
5 commandsgit logbeginnerShow the commit history
git show <commit>beginnerShow the details and diff of a specific commit
git blame <file>intermediateShow who last modified each line of a file
git diff <a>..<b>intermediateCompare two commits or branches
git bisect startadvancedBinary-search commit history to find a bug-introducing commit
Tags & Releases
4 commandsgit tagbeginnerList all tags
git tag -a <name> -m "<msg>"intermediateCreate an annotated tag for a release
git push <remote> <tag>intermediatePush a tag to the remote
git tag -d <name>intermediateDelete a local tag