Skip to content
rajin

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 -sb
  • git diff
  • git diff --staged
  • git log --all --graph --oneline --decorate

Prepare changes

  • git add PATH
  • git add -p
  • git restore --staged PATH

restore --staged preserves disk edits.

Save history

  • git commit -m MESSAGE
  • git commit --amend

Amend only when rewriting is acceptable.

Compare historical versions

  • git show REV:PATH
  • git diff A B
  • git log A..B

Navigate and branch

  • git switch BRANCH
  • git switch -c NAME
  • git switch --detach REV
  • git branch NAME REV

Combine work

  • git merge --ff-only TARGET
  • git merge TARGET
  • git rebase TARGET
  • git cherry-pick REV

--ff-only for undiverged histories; merge or rebase per team policy; cherry-pick for a selected change.

Undo safely

  • git revert REV
  • git reset
  • git restore --staged PATH
  • git 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 origin
  • git push

Fetch, inspect divergence, integrate, then push. Avoid blind force pushes.

Recover

  • git reflog
  • git branch rescue REV
  • git 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

Object ID
Hash-based identity of a serialized Git object.
5. Hashing and blob objects
Blob
Object storing file contents without a filename.
5. Hashing and blob objects
Tree
Directory snapshot mapping names, modes and object IDs.
6. Trees and directory structures
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
DAG
Directed acyclic graph; commit edges point to parents.
13. Commit graphs and movable references
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
Refspec
Source-to-destination mapping for references.
24. Upstream branches and refspecs
Reflog
Local log of ref updates when enabled.
28. Reflog, fsck and disaster recovery
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)

Reset modes
ModeEffect
--softref moves; Index and working tree stay.
--mixedref and Index change; working tree stays.
--hardref, 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.

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