Bisect, Worktrees, Submodules, LFS and Hooks
Advanced Git is about tools for finding regressions, juggling several checkouts, composing repositories, handling large files, automating with hooks and plumbing, and knowing which of these are local conveniences versus enforceable controls.
Key points
- 1
git bisectbinary-searches history;bisect runuses exit codes: 0 good, 125 skip, 1–127 bad, ≥128 aborts. - 2
Worktrees share objects and refs but each has its own HEAD, index and files; a branch can be checked out in only one worktree.
- 3
Submodules are gitlinks (mode 160000) pinning a commit; clone with
--recurse-submodulesor rungit submodule update --init --recursive. - 4
Git LFS stores ~130-byte pointers in history; without LFS installed (or
lfs: truein CI) you get the pointer text instead of the file. - 5
Hooks are never cloned; share them via
core.hooksPathor a hook manager, and enforce policy server-side or in CI because--no-verifyskips client hooks. - 6
Scripts should use plumbing and porcelain modes:
status --porcelain,rev-parse --verify --quiet,for-each-ref, and exit codes likediff --quiet. - 7
For huge repos: partial clone (
--filter=blob:none), cone-mode sparse checkout, andgit maintenancekeep things fast without losing history.
Common traps
Setting
core.hooksPathmakes Git ignore everything still in.git/hooks/.Commits made inside a submodule on a detached HEAD become unreachable after the next
submodule update.git lfs trackdoesn't shrink existing history; onlygit lfs migrate import(a history rewrite) does.
Test yourself on Bisect, Worktrees, Submodules, LFS and Hooks
Ten questions, with the answer and explanation after each one.