`git fetch` fails with `error: cannot lock ref 'refs/remotes/origin/main': is at 3f2a9c1 but expected 9c1d7e2`.
IntermediateTroubleshootingRepository Health, Size and Performance
Answer
Likely causes → Two fetches raced (IDE auto-fetch plus your terminal, or two CI steps in the same workspace), or two remote branches differ only by case (Feature/x vs feature/x) on a case-insensitive filesystem and keep overwriting the same file.
Diagnose →
git ls-remote --heads origin | awk '{print tolower($2)}' | sort | uniq -d # case collisions
ps aux | grep -E 'git (fetch|remote-https)'
Fix → Wait for the other fetch and retry. For case collisions, delete one of the colliding branches on the server, then git remote prune origin and git pack-refs --all.
Prevent → Disable aggressive IDE auto-fetch on shared workspaces, enforce lowercase branch names with a ruleset or naming check, and serialize Git steps in CI.
More on Repository Health, Size and Performance
`git status` takes 8–15 seconds in a large monorepo.Intermediate`error: The last gc run reported the following. Please correct the root cause and remove .git/gc.log` followed by `warning: There are too many unreachable loose objects; run 'git prune' to remove them.`IntermediateEvery few commands Git prints `Auto packing the repository in background for optimum performance.` and the machine stutters.BeginnerA fresh clone downloads 4 GB, but the checked-out files are only 200 MB.Intermediate`git gc` or `git clone` dies with `fatal: Out of memory, malloc failed (tried to allocate 1073741824 bytes)` or `error: pack-objects died of signal 9`.Advanced`error: unable to create temporary file: No space left on device` followed by `fatal: failed to write object`.Beginner