6

The full error is:

remote: error: cannot lock ref 'refs/heads/fix/add_overlay': reference already exists

I'm using SourceTree, but that should not matter I don't think. I keep trying to push and I keep getting this error, how can I resolve it?

Mike6679
  • 5,229
  • 17
  • 59
  • 105

3 Answers3

4

TL;DR: try removing their branch fix, i.e., their refs/heads/fix, which I suspect is in the way. (Be sure they don't care if you remove it!)


The error message is very odd. If the reference refs/heads/fix/add_overlay exists, that's not a problem! Git should be able to lock it, and if it can't, the reason it can't is not "because it exists".

I suspect that this may be a misleading error message: it may be that the reference refs/heads/fixnot refs/heads/fix/add_overlay—exists, so it's impossible to create a directory refs/heads/fix/ in which to hold the sub-reference refs/heads/fix/add_overlay because the existing reference refs/heads/fix is in the way.

You can tell whether this is the case by examining the set of references that exist (by using git ls-remote, or after a git fetch -p, by looking at your own set of remote-tracking names that are based on their branch names). And, if it is the case, you should convince them—whoever they are—to rename or remove their branch fix so that you can have them create a directory named fix/ containing branch names like fix/add_overlay.

torek
  • 389,216
  • 48
  • 524
  • 664
  • I have pushed to this branch ( refs/heads/Fix/add_overlay ) before so now it does exist as a remote branch...but why would it be locked? – Mike6679 Dec 08 '17 at 13:09
  • I'm going to have the admin reboot our git server because I agree this issue and error message is very odd – Mike6679 Dec 08 '17 at 15:06
  • 4
    You spelled `Fix` in uppercase in your comment here. Is it possible there is a case sensitive `fix` vs `Fix` and some sort of case folding issue on the server? – torek Dec 08 '17 at 16:22
  • reboot did not fix it either – Mike6679 Dec 08 '17 at 16:30
  • torek, you are right... in my remotes I see a 'fix' folder and a ''Fix" folder. Locally, my branch is under ''fix" and the remote version of my branch is under "Fix" ....how that happened, I have no idea. Is there way when pushing to specify the remote branch? – Mike6679 Dec 08 '17 at 16:47
  • ah ha! when pushing I was able to specify the remote branch folder name as "Fix" and not "fix" and then push succeeded. – Mike6679 Dec 08 '17 at 16:50
  • It's generally a bad idea to have branch names that differ only in case (upper vs lower), including directory names. Linux and Unix systems tend to be case-sensitive, so `a/b` and `A/b` and `a/B` and `A/B` name four different files; Windows and Mac file systems tend to do case-folding and you cannot store all four of those. This makes life miserable. The solution is to avoid the situation entirely. :-) – torek Dec 08 '17 at 16:55
  • yep, absolutely I agree, not sure who in my team used upper case...I always use lower case for folders. – Mike6679 Dec 08 '17 at 18:02
  • I ran into this exact problem and you explained it perfectly for me. Thank you – heez Nov 18 '21 at 00:24
0

This error can occur when attempting to push to a folder with the same name as an existing branch.

https://stackoverflow.com/a/22630664/1803879

Tom Howard
  • 4,194
  • 1
  • 39
  • 45
0

To remove that error, navigate to your project directory and run git remote and then remove the origin by running git remote rm origin.Create a new repository, [assuming you use GitHub] by running git remote add origin https://github.com/your_user_name/your_repository_name.git, and push the changes to the remote server,git push -u origin master.This should work.

Gwamaka Charles
  • 1,024
  • 8
  • 9