Tools
Git Cheat Sheet — Essential Commands Reference
The Git commands that cover almost all everyday work, grouped by what you are trying to do.
Advertisement
Setup & config
git config --global user.name "Name"Set your commit namegit config --global user.email "you@example.com"Set your commit emailgit config --listShow all current settingsStarting a repo
git initCreate a new repository heregit clone <url>Copy a remote repository locallygit remote -vList configured remotesgit remote add origin <url>Attach a remote named originEveryday snapshotting
git statusShow changed and staged filesgit add <file>Stage a specific filegit add .Stage everything in the current directorygit commit -m "message"Commit staged changesgit commit -am "message"Stage tracked files and commit in one stepgit diffShow unstaged changesgit diff --stagedShow staged changesBranching & merging
git branchList local branchesgit switch -c <name>Create and switch to a new branchgit switch <name>Switch to an existing branchgit merge <branch>Merge a branch into the current onegit rebase <branch>Replay your commits on top of another branchgit branch -d <name>Delete a merged branchSyncing with a remote
git fetchDownload remote changes without merginggit pullFetch and merge remote changesgit pushUpload your commits to the remotegit push -u origin <branch>Push and set the upstream branchUndoing things
git restore <file>Discard local changes to a filegit restore --staged <file>Unstage a file, keeping the changesgit commit --amendRewrite the most recent commitgit revert <commit>Create a new commit undoing an old one (safe)git reset --hard <commit>Discard commits and changes (destructive)History & stashing
git log --oneline --graphCompact visual historygit show <commit>Show the contents of a commitgit blame <file>See who last changed each linegit stashShelve your uncommitted changesgit stash popReapply the most recently stashed changes