Developer Tools

Git Commands Cheat Sheet

Quick reference for daily Git commands: setup, branching, rebasing, cherry-picking, stashing, inspecting history, tags, and undoing changes safely.

1 min readUpdated 2026-11-30

Setup & Identity

bash
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git init -b main
git clone https://github.com/org/repo.git

Branching, Merging & Rebasing

bash
git branch -a                    # List local and remote branches
git switch -c feat/new-feature   # Create and switch to branch
git switch main                  # Switch back to main
git merge feat/new-feature       # Merge branch into current branch
git branch -d feat/new-feature   # Safe-delete merged branch
git pull --rebase origin main    # Replay local commits onto latest main

Staging, Committing & Syncing Forks

bash
git status
git diff                         # Unstaged changes
git diff --staged                # Changes ready for next commit
git add -p                       # Stage changes interactively chunk-by-chunk
git commit -m "Clear imperative summary"
git push -u origin feat/new-feature
git fetch upstream && git merge upstream/main

Stashing, Cherry-Pick & Releases

bash
git stash push -u -m "wip: auth" # Stash tracked + untracked files
git stash list
git stash show -p stash@{0}      # Inspect stash diff
git stash pop                    # Restore and remove from stash
git cherry-pick <commit-sha>     # Copy one specific commit onto current branch
git tag -a v1.0.0 -m "Release"   # Create annotated release tag

History Investigation & Safe Undo

GoalCommand
Find when a symbol was added/removedgit log -S "symbolName" --oneline
View last 3 commits touching a filegit log -p -n 3 path/to/file
Discard unstaged changes in a filegit restore <file>
Unstage a file (keep edits)git restore --staged <file>
Undo last local commit (keep edits)git reset --soft HEAD~1
Revert a pushed commit safelygit revert <commit-sha>