Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git fatal: Reference has invalid format: 'refs/heads/master

Tags:

git

dropbox

I am using Dropbox to sync a git repository, but now when I try and push I am getting an error:

fatal: Reference has invalid format: 'refs/heads/master (MacBook-Pro's conflicted copy 2012-10-07)' 

So, it seems that Dropbox detected a conflict and created a copy. Ok, no problem, so I deleted the conflicted file. Still, getting the above git error though.

$ git checkout master     M   index.html     Already on 'master' $ git add . $ git commit -a -m "Cleanup repo"     [master ff6f817] Cleanup repo     1 file changed, 5 insertions(+), 5 deletions(-) $ git push     fatal: Reference has invalid format: 'refs/heads/master (MacBook-Pro's conflicted copy 2012-10-07)'     The remote end hung up unexpectedly` 

How can I fix this? Thanks.

like image 984
Justin Avatar asked Oct 07 '12 22:10

Justin


2 Answers

make a backup of your repo if you aren't sure about this one, because these commands are irreversible.

first, go to your repo directory.

cd myrepo 

then recursively search for the conflicted files and delete them

find . -type f -name "* conflicted copy*" -exec rm -f {} \; 

lastly, remove any "conflicted" references from git's packed-refs file

awk '!/conflicted/' .git/packed-refs > temp && mv temp .git/packed-refs 
like image 158
Lane Avatar answered Sep 20 '22 17:09

Lane


The conflicted file could be in multiple places, I would look into:

.git/logs/refs/remotes/origin/ .git/logs/refs/heads/ .git/refs/remotes/origin/ .git/refs/heads/ 

Or you might look everywhere in the .git subdirectory: find . -name '*conflicted*'

Or, otherwise, list the active branches with git branch -a and delete (git branch -d) anything suspicious.

like image 43
Marco Leogrande Avatar answered Sep 22 '22 17:09

Marco Leogrande