Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git fatal: bad object refs/heads 2/master

Tags:

git

github

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?

like image 487
A. Maman Avatar asked Mar 18 '26 21:03

A. Maman


1 Answers

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
like image 86
Robin Stewart Avatar answered Mar 21 '26 11:03

Robin Stewart