Git fatal: cannot lock ref

Viewed 81674

I'm trying to create a branch on the current branch on my Ubuntu guest. Unfortunately I keep getting this error:

git checkout -b origin/feature/IF-53-change-validation-window/Tommaso
fatal: cannot lock ref 'refs/heads/origin/feature/IF-53-change-validation-window/Tommaso': 
'refs/heads/origin/branch' exists; 
cannot create 'refs/heads/origin/branch/Tommaso'

I tried git gc --prune=now as suggested here link, but keep getting the same error.

9 Answers

This worked for me :

git --no-optional-locks fetch --prune origin 

Sometimes this can happen if the name of the branch you create doesn't match git naming conventions or those set by you projects git administrator. Changing the name to one that does, can can fix this issue.

I was looking for answer here, but actually my problem was simpler, yet unresolvable.

  • fresh clone of repo
  • git checkout foo/bar
  • git checkout -b foo/bar/baz
  • got similiar error message.

As described here, you cannot use foo/bar both as a branch and directory. I had to change proposed naming convention.

This happened with me too. The reason was, I was checking out a branch named feature, but in my local I already had a branch called feature/new-feature.

After trying some of the above solutions with no luck, this worked for me:

git gc --prune=now

This happend to me, too. The reason was that I tried to create a branch with a too deep directory. The deepest directory to successfully create was: origin/titleA/titleB/nameOfTheNewBranch and I first tried to create it one step deeper in origin/titleA/titleB/titleC/nameOfTheNewBranch which seemed to be too deep 'cause it does not work.

refs/heads The HEAD file is usually a symbolic reference to the current branch. The so-called symbolic reference means that it is a pointer to another reference.

every branch you make(such as s/a/b/c/d) will create a path in refs/heads. A file name d which save a SHA-1 values would be touch in the path: refs/heads/s/a/b/c/d

so the problem is, you made a branch named "origin/branch" already, so you can t make any branch named "origin/xxxxx" (or "origin/branch/xxxx") any more

I just go a similar problem and the reason is, because of deleting the branch on the repo I couldn't access it to local so , what I do is delete the local branch and pull the new branch from the repo then create the feature branch and it did work

  • if you delete the branch in the repo it is still available in local
Related