3

How can I solve this error when I run git pull in Terminal on a Mac?

remote: Enumerating objects: 115, done. remote: Counting objects: 100% (115/115), done. remote: Compressing objects: 100% (66/66), done. remote: Total 104 (delta 71), reused 63 (delta 30), pack-reused 0 Receiving objects: 100% (104/104), 3.92 MiB | 3.16 MiB/s, done. Resolving deltas: 100% (71/71), completed with 9 local objects. fatal: bad object refs/heads/main (1) error: https://github.com/[...domain name...]/website.git did not send all necessary objects 

The background is that I have a website that usually works with no problem. I created it in RStudio and sync it with github. Netlify goes from there. Here is what the setup is based on: https://www.apreshill.com/blog/2020-12-new-year-new-blogdown/.

After I make changes in RStudio, from within RStudio, I can usually just commit and then push the changes. But this time, it says this:

 ! [rejected] HEAD -> main (non-fast-forward) error: failed to push some refs to 'https://github.com/[domain name]/website.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again 

So I go to Terminal and change the working directory to where the files are stored and run git pull. I then get the fatal: bad object refs/heads/main (1) error mentioned above. Based on How to handle git gc fatal: bad object refs/remotes/origin/HEAD error?, I tried git gc and get this error:

error: bad ref for .git/logs/HEAD (1) error: bad ref for .git/logs/refs/heads/main (1) fatal: bad object refs/heads/main (1) fatal: failed to run repack 

I also tried git remote set-head origin --auto and then git gc and get the same error as directly above.

If I run cat .git/refs/remotes/origin/HEAD, it says: refs/remotes/origin/main.

Finally, I tried git reset --hard before git pull and this gives me the original error.

I am not sure what to do at this point. I am totally fine to get everything from the remote server and redo my local changes.

4
  • Have you looked inside the .git/refs/heads/main file? Commented Jan 12, 2023 at 15:04
  • That file does not exist locally. But the .git/refs/heads/main (1) file contains only a single line. It is a long string of letters and numbers. Commented Jan 12, 2023 at 15:08
  • 1
    The (1) suffix in the filename is strange. Maybe it was added accidentally by OS. Try to delete it from the filename. Commented Jan 12, 2023 at 15:15
  • Ah - I deleted ` (1), did git reset --hard HEAD, then git pull`, and it all works now! Thanks. Commented Jan 12, 2023 at 19:59

1 Answer 1

7

In your repository a file named .git/refs/heads/main (1) exists, which also means that local branch main (1) exists. The name contains a space which is not allowed in branch names (see here), which is probably the cause of error.

The (1) suffix probably emerged accidentally. Try to remove it from file names first and then run other operations.

Sign up to request clarification or add additional context in comments.

2 Comments

Probably what happened is that for some reason the main (1) file got created by Google Drive.
Yeah, for me this keeps happening with new Dropbox set-up for some reason, conflicting heads.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.