Git and nasty "error: cannot lock existing info/refs fatal"

After cloning from remote git repository (at bettercodes) I made some changes, commited and tried to push:

git push origin master

Errors with:

error: cannot lock existing info/refs
fatal: git-http-push failed

This case regards already existing repository.

What I did before, was:

  1. git config –global http.sslVerify false
  2. git init
  3. git remote add [url]
  4. git clone
  5. change data
  6. git commit

At 'bettercodes' I have no access to git log.

I'm using Windows. The detailed error was:

C:\MyWorkStuff\Projects\Ruby\MyProject\>git push origin master
Unable to create branch path https://user:[email protected]/myproject/info/
error: cannot lock existing info/refs
fatal: git-http-push failed

I cloned before, then changed the code and committed.


For me this worked (won't change in remote):

git remote prune origin

Since this answer seems to help a lot of people, I dug a little bit into what actually happens here. What this will do is remove references to remote branches in the folder .git/refs/remotes/origin.

So this will not affect your local branches and it will not change anything remote, but it will update the local references you have to remote branches. It seems in some cases these references can contain data Git cannot handle correctly.


You want to try doing:

git gc --prune=now

See https://www.kernel.org/pub/software/scm/git/docs/git-gc.html


This happened to me when my git remote (bitbucket.org) changed their IP address. The quick fix was to remove and re-add the remote, then everything worked as expected. If you're not familiar with how to remove and re-add a remote in git, here are the steps:

  1. Copy the SSH git URL of your existing remote. You can print it to the terminal using this command:

    git remote -v

which will print out something like this:

 origin [email protected]:account-name/repo-name.git (fetch)
 origin [email protected]:account-name/repo-name.git (push)
  1. Remove the remote from your local git repo:

    git remote rm origin

  2. Add the remote back to your local repo:

    git remote add origin [email protected]:account-name/repo-name.git


This is what I did to get rid of all the lock ref issues:

git gc --prune=now
git remote prune origin

This is probably what you only need to do too.

More about git gc command here: https://git-scm.com/docs/git-gc

More about git remote prune here: https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-empruneem


Running command git update-ref -d refs/heads/origin/branch fixed it.