Interview Prep/Git & GitHub/Repository Health, Size and Performance

`git fsck` reports `broken link from commit 1a2b3c4... to tree 4d5e6f7...` and `missing tree 4d5e6f7...`.

AdvancedTroubleshootingRepository Health, Size and Performance
Answer

Likely causes → Objects are genuinely missing: disk or filesystem corruption, a repo copied while Git was writing, an interrupted git gc on a network filesystem, or an objects/info/alternates file pointing at a repo that has since been deleted or pruned.

Diagnose →

git fsck --full
cat .git/objects/info/alternates 2>/dev/null
git cat-file -t 4d5e6f7

Fix → Missing objects can only be restored from another copy. If the remote has them, re-fetch into a fresh clone and move over local branches, or copy objects back:

git clone --mirror [email protected]:org/repo.git /tmp/good.git
git --git-dir=/tmp/good.git cat-file -p 4d5e6f7 >/dev/null && echo "remote has it"
cp -rn /tmp/good.git/objects/pack/* .git/objects/pack/
git fsck --full

If an alternate was removed, run git repack -a -d from a working copy before deleting the alternate next time.

Prevent → Never copy or sync a live .git with rsync/Dropbox, avoid alternates in shared setups, and keep backups (mirror clones).

All Git & GitHub questions Roadmap: Git & GitHub

More on Repository Health, Size and Performance