Cheat Sheet

Git Cheat Sheet

The most-used Git commands grouped by task.

Setup

git config --global user.name "Name"Set committer name
git config --global user.email you@example.comSet committer email
git initInitialize a new repository
git clone <url>Clone a remote repository

Daily Workflow

git statusShow changes
git add <file> / git add .Stage files
git commit -m "message"Commit staged changes
git commit -am "message"Stage tracked + commit
git push / git pullPush or pull current branch
git fetch --all --pruneFetch and prune deleted remote branches

Branches

git branchList branches
git switch -c <name>Create + switch to a new branch
git switch <name>Switch to a branch
git merge <branch>Merge into current
git rebase <branch>Rebase current onto branch
git branch -d <name>Delete a merged branch

History & Inspection

git log --oneline --graph --decorate --allCompact graph of all branches
git diff / git diff --stagedUnstaged / staged changes
git show <commit>Show a commit
git blame <file>Who changed each line

Undoing

git restore <file>Discard working changes
git restore --staged <file>Unstage a file
git commit --amendAmend last commit
git revert <commit>Reverse a commit safely
git reset --hard <commit>Discard all changes back to a commit

Stash

git stash push -m "msg"Save working changes
git stash listList stashes
git stash popRe-apply most recent + drop

Tags & Remotes

git tag v1.2.3Create a lightweight tag
git tag -a v1.2.3 -m "msg"Annotated tag
git push --tagsPush tags
git remote -vList remotes
git remote add origin <url>Add a remote