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.
Further reading
Suggest a resource- git-worktree documentation(opens in a new tab)Checking out several branches at once in linked working trees.Docsgit-scm.comEditor’s pick
- git-sparse-checkout documentation(opens in a new tab)Checking out only part of a large repository.Docsgit-scm.comEditor’s pick
- Get up to speed with partial clone and shallow clone(opens in a new tab)How blobless, treeless and shallow clones differ and when to use each.Articlegithub.blogEditor’s pick
Test yourself on Bisect, Worktrees, Submodules, LFS and Hooks
Ten questions, with the answer and explanation after each one.