Notorious Git Error: remote rejected (failed to lock)

What happened to me was that git was changing the capitalization of my local branch. I had an old branch named Feature/blahBlah and a new branch named feature/fooBar. The latter was renamed automatically to Feature/fooBar since git stores branches as folders and I couldn't have the same folder name with different capitalization.

To fix it, I had to go into .git/refs/heads and rename 'Feature' to 'feature'` so all branches would be consistent.


Another possible reason of problems present also on case sensitive systems is conflicting breaches names.

If remote repository contains branch a/b and you are trying push branch a/b/c same error will be reported by git (definitely this error description should be improved).

https://coderwall.com/p/qkofma/a-caution-about-git-branch-names-with-s https://ocroquette.wordpress.com/2011/07/10/git-failed-to-lock/


I saw this error happen because a previous branch existed with the same name as my new branch path name. Example:

  • Remote has branch: some_feature
  • Local has branch: some_feature/some_subfeature
  • Local pushes branch some_feature/some_subfeature to Remote
  • Remote has error: (failed to lock)

Solutions:

  • Rename local branch some_feature/some_subfeature to foo/some_subfeature
  • Delete remote branch some_feature

 git push feature/prizeFulfilment: feature/Prizefulfilment

That is similar to this answer:

For the record, I believe the root cause of this problem was the difference in capitalisation between the local and remote branch names, and the case-insensitive nature of the Windows share that hosted the remote repository.

We just encountered this exact same error and were able to resolve the problem simply by renaming the local branch to match the capitalisation of the existing remote branch.

Try and make sure to use the same capitalization between local and remote branches.

You second command make the link between the prizeFulfilment and remote Prizefulfilment explicit, which is why it worked. But it isn't a good solution to keep a local branch with that kind of difference.

Tags:

Git

Github