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:

  • Remove a file from git locally, but not on remote
  • Why does git push fails with “Operation timed out”?
  • Sublime Text won't automatically change code, when I switched to different branch
  • Rewrite git repository history by deleting all files but “foo” and “bar”
  • Does Accurev support stashing?
  • How to get changed lines only in diff in TortoiseGit or with Windows?
  • 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:password@git.bettercodes.org/myproject/info/
    error: cannot lock existing info/refs
    fatal: git-http-push failed
    

    I cloned before, then changed the code and committed.

  • Nested Git submodules not cloning properly with --recursive flag
  • What does it mean when Git diff shows mode changes?
  • How to merge upstream on GitHub as a submodule?
  • How to push local postgresql database built on rails to heroku?
  • How can I debug git/git-shell related problems?
  • How to remove range of git stash?
  • 11 Solutions collect form web for “Git and nasty “error: cannot lock existing info/refs fatal””

    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 git@server-address.org:account-name/repo-name.git (fetch)
     origin git@server-address.org: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 git@server-address.org:account-name/repo-name.git

    You want to try doing:

    git gc --prune=now
    

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

    For me this worked:

    git remote prune origin

    I fixed this by doing the following

    git branch --unset-upstream
    rm .git/refs/remotes/origin/{branch}
    git gc --prune=now
    git branch --set-upstream-to=origin/{branch} {branch}
    #or git push --set-upstream origin {branch}
    git pull
    

    This assuming that your local and remote branches are aligned and you are just getting the refs error as non fatal.

    This is probably resolved by now. But here is what worked for me.

    1. Location:

      • If locked repository is on the server-side:

        1. ssh to your git repository on the server.
        2. Login as user which has permissions to modify the repository and navigate to the repository on your server.
      • If locked repository is local only:

        1. Open the git console and navigate to the repository directory.
        2. Run this command:

          git update-server-info
          
    2. Fix the permissions on your (remote or/and local) repository if you have to. In my case I had to chmod to 777 and chown to apache:apache

    3. Try to push again from the local repository:

      git push
      

    This is how it works for me.

    1. look up the Apache DAV lock file on your server (e.g. /var/lock/apache2/DAVlock)
    2. delete it
    3. recreate it with write permissions for the webserver
    4. restart the webserver

    Even faster alternative:

    1. look up the Apache DAV lock file on your server (e.g. /var/lock/apache2/DAVlock)
    2. Empty the file: cat /dev/null > /var/lock/apache2/DAVlock
    3. restart the webserver

    This sounds like a permissions issue – is it possible you had two windows open, executing with separate rights? Perhaps check ownership of the .git folder.

    Perhaps check to see if there is an outstanding file lock open, maybe use lsof to check, or the equivalent for your OS.

    Check that you (git process actually) have access to file .git/info/refs and this file isn’t locked by another process.

    Update:

    You might need to edit your ~/.netrc file:

    https://bugs.launchpad.net/ubuntu/+source/git-core/+bug/293553

    Original answer:

    Why did you disable ssl? I think this might have to do with you not being able to push via https. I’d set it back and try to push again:

    git config –global http.sslVerify true
    

    In case of bettercodes.org, the solution is more poetic – the only problem may be in rights assigned to the project members. Simple members don’t have write rights! Please make sure that you have the Moderator or Administrator rights. This needs to be set at bettercodes.org at the project settings by an Administrator, of course.

    In my case a branch was moved to a subdirectory and the directory was called as the branch. Git was confused by that. When I deleted the local branch (in SourceTree just with right click delete) everything worked as usual.

    Git Baby is a git and github fan, let's start git clone.