Quick reference
Git reference
Searchable glossary, decision guide and plumbing guide from the handbook (pp. 92–95).
Recall the definition first, then read it.
Decide before you type
Name the state or relationship you want to change. Inspect first; preserve valuable data. (p. 92)
Inspect the current state
git status -sbgit diffgit diff --stagedgit log --all --graph --oneline --decorate
Prepare changes
git add PATHgit add -pgit restore --staged PATH
restore --staged preserves disk edits.
Save history
git commit -m MESSAGEgit commit --amend
Amend only when rewriting is acceptable.
Compare historical versions
git show REV:PATHgit diff A Bgit log A..B
Navigate and branch
git switch BRANCHgit switch -c NAMEgit switch --detach REVgit branch NAME REV
Combine work
git merge --ff-only TARGETgit merge TARGETgit rebase TARGETgit cherry-pick REV
--ff-only for undiverged histories; merge or rebase per team policy; cherry-pick for a selected change.
Undo safely
git revert REVgit resetgit restore --staged PATHgit restore PATH
Shared commit: git revert REV. Local rewrite: choose reset mode deliberately. Unstage: restore --staged; discard disk edits: restore PATH (destructive).
Synchronize
git fetch origingit push
Fetch, inspect divergence, integrate, then push. Avoid blind force pushes.
Recover
git refloggit branch rescue REVgit fsck --full --no-reflogs --unreachable
Copy the repo first; inspect blobs before restoring them.
Plumbing and state guide
git hash-object -w --stdin- Create or reuse a content-addressed blob.
git cat-file -t ID / git cat-file -p ID- Inspect an object type or pretty-print its content.
git ls-files --stage / git ls-files -u- Inspect Index entries and unresolved conflict stages.
git write-tree / git commit-tree TREE -p PARENT- Create a tree from the Index; create a commit with a parent.
git rev-parse REV / git symbolic-ref HEAD- Resolve an object name; inspect symbolic HEAD.
git update-ref REF ID / git show-ref- Safely update a ref; list references.
git merge-base A B / git worktree list- Find a best common ancestor; list linked worktrees.
git verify-pack -v PACK.idx / git count-objects -v- Inspect packed object storage and counts.
Glossary
- Commit
- Object identifying a root tree, parent(s), metadata and message.
- 7. Commit objects and immutability
- Ref
- Name identifying an object; branch refs usually identify commits.
- 3. The big picture of Git architecture13. Commit graphs and movable references
- Index
- Prepared path-to-object entries, plus metadata and conflict stages.
- 9. Working directory, Index and HEAD10. What add and commit actually do
- Merge base
- Best common ancestor of commits; there may be several.
- 17. Fast-forward and three-way merging
- Remote-tracking ref
- Local record of a remote branch state, updated by configured operations.
- 22. Cloning and remote repositories23. Fetch, pull and push
- Packfile
- Compact representation of many Git objects, possibly using deltas.
- 26. Packfiles and delta compression
- Reachability
- Whether an object can be reached by traversing links from roots.
- 27. Reachability and garbage collection
- Porcelain / plumbing
- High-level workflow commands / lower-level inspection and operations.
- 3. The big picture of Git architecture
Reset at a glance (commit-level)
| Mode | Effect |
|---|---|
| --soft | ref moves; Index and working tree stay. |
| --mixed | ref and Index change; working tree stays. |
| --hard | ref, Index and working tree change; can discard data. |
Critical distinction. A branch backup preserves commits, not arbitrary working-tree edits. Inspect and preserve those separately before any history rewrite.
Sources and validation
This second edition expands the supplied 17-page handbook. Its teaching structure, examples, caveats and exercises are an editorial redesign, not an official Git publication.
- Pro Git, 2nd edition: Git internals and packfiles
- Git official manuals: command semantics and repository formats
- Git user manual: object format and repository model
- Git fetch and push: refspecs and explicit leases
- Git reflog: expiration and local ref history
- Git reftable: alternative reference storage
Dunlosky, J. et al. (2013). Improving Students’ Learning With Effective Learning Techniques. Psychological Science in the Public Interest, 14(1), 4–58. DOI: 10.1177/1529100612453266. Practice testing and distributed practice inform the revision plan.
The visual models, short lesson cycle, mixed practice and progressive challenges are instructional design choices; their effectiveness for this specific handbook has not been measured in a learner study.
Handbook verification scope. All 32 companion lab/reference scripts completed successfully in a Linux sandbox with Git 2.47.3. Independent exercises and alternate paths were not exhaustively tested. Windows/macOS, other Git versions and custom configurations may differ. No live remote service is required.
This web edition. This web edition re-runs every guided lab and independent-challenge verifier against real Git: locally in CI with the system Git, and inside the Alpine sandbox image the labs actually use.
Further practice: Learn Git Branching · Git Immersion