How to clear git caches?
Use git fetch -p
to prune your local caches
I had a weird issue on macOS where I would get phantom Uppercase versions of branches, e.g. my remote branch listing would show Ben/some-branch
locally, but the server would show ben/some-branch
.
git remote prune origin
would (correctly) remove them, but git fetch --prune
would (incorrectly) bring them right back. Very weird.
Best I can tell, at some point in the past, I had a Ben/something
branch, but because the default macOS filesystem is case-insensitive, the .git
metadata was hanging onto a (capitalized) .git/refs/remotes/origin/Ben
folder and using it for the (lowercase) remote branch refs.
rm -rf .git/refs/remotes/origin/Ben && git fetch
put me back in order.
Like mentioned on cleaning up old remote git branches, you should use git remote prune origin
.
I didn't use the other two commands mentioned there.