Git Commands
Task-oriented Git reference — not a tutorial. Assumes a remote named origin and default branch main.
Basics
| Command | Purpose |
|---|---|
git status -sb | Short branch-aware status |
git diff | Unstaged changes |
git diff --staged | Staged changes |
git add -p | Interactive stage hunks |
git commit --amend | Rewrite last commit (use carefully if pushed) |
Branches
| Command | Purpose |
|---|---|
git switch -c feature/x | Create and checkout branch |
git branch -vv | List with upstream tracking |
git merge --no-ff feature/x | Merge preserving branch bubble |
git rebase main | Replay current branch on top of main |
Undo & recovery
| Command | Purpose |
|---|---|
git restore file | Discard unstaged changes (2.23+) |
git restore --staged file | Unstage |
git reset --soft HEAD~1 | Drop last commit, keep changes staged |
git reflog | Find lost commits after rebase/reset |
Stash & remote
git stash push -m "wip" -- path/to/file
git pull --rebase origin main
git push -u origin feature/x