Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Push Error "cannot lock ref" "reference already exists"

Tags:

git

push

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?

like image 272
Mike6679 Avatar asked Apr 26 '26 08:04

Mike6679


2 Answers

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.

like image 56
torek Avatar answered Apr 28 '26 21:04

torek


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.

like image 25
Gwamaka Charles Avatar answered Apr 28 '26 21:04

Gwamaka Charles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!