Command Reference
A quick-lookup cheat sheet. See the linked page for each section for full
explanations and examples.
| Command | Description |
git config --global user.name "..." | Set your commit author name |
git config --global user.email "..." | Set your commit author email |
git init | Create a new, empty repository |
git clone <url> | Copy an existing repository |
| Command | Description |
git status | Show staged / unstaged / untracked files |
git add <path> | Stage a file or directory |
git add -p | Interactively stage hunks |
git commit -m "..." | Record a snapshot |
git commit --amend | Edit the most recent commit |
git diff | Working dir vs. staging area |
git diff --staged | Staging area vs. last commit |
git log --oneline --graph --all | Compact history graph |
git show <sha> | Full details of one commit |
git rm / git mv | Remove / rename a tracked file |
| Command | Description |
git branch | List local branches |
git switch -c <name> | Create and switch to a branch |
git branch -d <name> | Delete a merged branch |
git merge <branch> | Merge a branch into the current one |
git merge --abort | Cancel a merge with conflicts |
| Command | Description |
git remote add origin <url> | Add a remote |
git fetch | Download commits, don't merge |
git pull | Fetch + merge current branch's upstream |
git push -u origin <branch> | Push and set upstream tracking |
git push --force-with-lease | Safe force-push after history rewrite |
| Command | Description |
git restore <file> | Discard unstaged changes |
git restore --staged <file> | Unstage a file |
git reset --soft HEAD~1 | Undo last commit, keep changes staged |
git reset --hard <commit> | Discard everything after a commit |
git revert <sha> | Undo a commit with a new, safe commit |
git reflog | Recover a "lost" commit |
| Command | Description |
git stash | Shelve uncommitted changes |
git stash pop | Reapply and remove the latest stash |
git stash list | Show the stash stack |
| Command | Description |
git tag -a v1.0.0 -m "..." | Create an annotated tag |
git push origin --tags | Push every local tag |
| Command | Description |
git rebase main | Replay current branch's commits on top of main |
git rebase -i HEAD~5 | Interactively edit/squash the last 5 commits |
git rebase --continue / --abort | Resume or cancel a paused rebase |
git cherry-pick <sha> | Apply one commit onto the current branch |
Inspecting & searching
| Command | Description |
git blame <file> | Who last changed each line, and in which commit |
git log -S"text" | Find commits that added/removed a string (pickaxe search) |
git bisect start | Binary-search history for the commit that introduced a bug |
git grep "pattern" | Search tracked files at the current checkout |