git: failed to lock

Recently I had this error message “failed to lock” while trying to push some changes to a remote Git repository.

After some time Googling with no success and then troubleshooting, I realised I was trying to push to branch called “a/b” while the branch “a” existed. This is obviously not supported by Git, since having a branch “a” requires “.git/refs/heads/a” to be a file (containing the current branch head), while having a branch “a/b” requires “.git/refs/head/a” to be a directory.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

6 Responses to git: failed to lock

  1. THANK YOU. This is the 2nd time this has happened. The first time I had to save a patch of my last commit, delete my local repo, repull, apply the patch and push. I just renamed my branch from tests/foo to just foo and magically it worked.

  2. ocroquette2 says:

    I am glad it helped, thank you for your comment!

  3. Thank you! First three hits in Google (for “git push failed to lock”) were from SO and they didn’t help me. Your post did 🙂

  4. ocroquette2 says:

    You’re welcome, thank you for your message.

  5. Aaron says:

    OMG, thank you! You just saved me SO much pain!

  6. Ryan Steele says:

    My local git repo’s branch was Feature instead of feature. Renaming the directory to the proper case solved the problem. Thank you for the post!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s