Git Modern Command Reference & Internal Architecture
High-density Git cheat sheet covering interactive staging, branch rebase workflows, reflog recovery, and visual branch architecture.
Core Commands & Staging
Staging files, interactive hunk commits, and status checking.
Interactive Staging & Commits
Selectively stage hunks and format conventional commits.
| Command | Scope | Working Tree Effect | Use Case |
|---|---|---|---|
| git add <path> | Selected file or path | None | Stage a complete intentional change |
| git add -p | Selected hunks | None | Split mixed edits into focused commits |
| git restore --staged <path> | Selected staged path | Keeps working-tree edits | Remove a file from the next commit |
| git diff | Unstaged changes | None | Review what remains outside the index |
| git diff --staged | Staged changes | None | Review the exact next commit |
git add -pInteractively prompts to stage individual code hunks instead of entire files
Use prefixes like feat:, fix:, docs:, refactor:, or test: for automated changelogs.
Branching & Interactive Rebase
Branch management, rebasing onto main, and interactive squashing.
Branch Workflows & Interactive Rebase
Maintain a clean linear git history with interactive rebasing.
git rebase -i HEAD~4Launches interactive editor to pick, reword, squash, or drop commits
Never rebase a public branch that other team members are actively pulling from.
Use git rebase --autostash to automatically stash uncommitted changes before rebasing.
Undo & Reflog Recovery
Recovering lost commits, soft/hard resets, and reflog time travel.
Git Reflog & Emergency Recovery
Recovering deleted branches or bad resets using HEAD history.
git reflogLogs every single HEAD movement locally, even for deleted branches or resets
Git keeps reflog entries for 90 days before garbage collection runs.
git reset --hard permanently discards uncommitted working directory changes.