After a few month not working on some static website, I came back and tried to pull changes from a GitHub repo.
The following fatal: bad object refs/heads 2/master error occured.
(base) ➜ github_repo git:(master) ✗ git pull
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 21 (delta 3), reused 3 (delta 3), pack-reused 18
Unpacking objects: 100% (21/21), 6.95 KiB | 790.00 KiB/s, done.
fatal: bad object refs/heads 2/master
error: https://github.com/asafmaman101/asafmaman101.github.io.git did not send all necessary objects
Tried some solutions for similar problems here from StackOverflow and tried also to update Git version on my mac.
Nothing helped. I'm trying to prevent from deleting local copy and re-cloning the repo because I have local changes that I don't want to lose. Any other ideas?
I had a similar problem with a " 2" suffix being added to a filename within the .git directory. The git repository is in a directory synced by iCloud Drive, so presumably iCloud in its infinite wisdom added the suffix during a sync operation.
I originally encountered the issue via a cryptic error message in SourceTree. Running git gc on the command line helped me narrow down the issue:
> git gc
fatal: bad object refs/heads/1.2 2
fatal: failed to run repack
I was able to fix the issue by removing the " 2" suffix:
> mv .git/refs/heads/1.2\ 2 .git/refs/heads/1.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With