Notorious Git Error: remote rejected (failed to lock)

Loading...

Notorious Git Error: remote rejected (failed to lock)

I am trying to push to a branch from my local to the origin. The branch name and the path is same. I have been pushing and pulling from this branch for a while and never had a problem. But suddenly, it started behaving badly. Last time when I tried to push to origin with following command:
git push origin feature/Prizefulfilment

It gives me following errror:
72c6c1da98e5cff4484e254a538d9e3b472156ff but expected 0000000000000000000000000000000000000000

I have Googled around but did not find a quite satisfying solution to it yet.
My exact error looks like following:
$ git push origin feature/Prizefulfilment
Counting objects: 126, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (78/78), 8.83 KiB, done.
Total 78 (delta 61), reused 0 (delta 0)
error: Ref refs/heads/feature/Prizefulfilment is at 72c6c1da98e5cff4484e254a538d9e3b472156ff but expected 0000000000000000000000000000000000000000
remote: error: failed to lock refs/heads/feature/Prizefulfilment
To git@devtools.contestfactory.com:OpusOneSCRUM
! [remote rejected] feature/Prizefulfilment -> feature/Prizefulfilment (failed to lock)
error: failed to push some refs to ‘git@devtools.contestfactory.com:OpusOneSCRUM’`

Any ideas?

Solutions/Answers:

Solution 1:

 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.

Solution 2:

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/

Solution 3:

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.

Solution 4:

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

Solution 5:

In my case it was permissions not set up correctly in the git repository. I found the solution here: How to use group file permissions correctly on a git repository?

The problem was when a new branch was created that contains a path (feature/Prizefulfilment), the folder “feature” is created in “refs/heads/” and the new folder had inherit the users group ID which prevented future users to use the same path.

To solve this you have to set the setgid to all of the directories in the git repository so that the new folder inherit its group ID, rather than group ID of the user.

chown -R git:git /path/to/repo
chmod -R g+rw /path/to/repo
find /path/to/repo -type d -print0 | xargs -0 chmod g+s

Solution 6:

In my case, I had checkout a branch with all lower case lettering. This caused an inconsistency between the remote branch and local branch names.

Remote branch was INT-4368-some-feature-details, whereas local branch was int-4368-some-feature-details.

To fix, I went into .git\refs\heads\feature and renamed the branch name to match the remote. Then went to command line and ran

git checkout INT-4368-some-feature-details

References

Loading...