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

Git

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

You want to try doing:

git gc --prune=now

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

Solution 3 - Git

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)

2. Remove the remote from your local git repo:

 `git remote rm origin`

3. Add the remote back to your local repo:

`git remote add origin git@server-address.org:account-name/repo-name.git`

Solution 4 - 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

Solution 5 - Git

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

Solution 6 - Git

What worked for me was:

  1. Remove .git/logs/refs/remotes/origin/branch
  2. Remove .git/refs/remotes/origin/branch
  3. Run git gc --prune=now

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

Solution 7 - Git

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.

Solution 8 - Git

Before pull you need to clean your local changes. following command help me to solve.

git remote prune origin

and then after

git pull origin develop

Hopes this helps!

Solution 9 - Git

I had this issue because I was on a branch that had a similar name to an upstream branch. i.e. the upstream branch was called example-branch and my local branch was called example-branch/backend. The solution was changing the name of my local branch like so:

git branch -m <new name goes here>

Solution 10 - Git

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
      
  1. 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

  2. Try to push again from the local repository:

     git push
    

Solution 11 - Git

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.

Solution 12 - Git

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

Solution 13 - Git

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.

Solution 14 - Git

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

Solution 15 - Git

In my case after getting this message I did the checkout command and was given this message:

Your branch is based on 'origin/myBranch', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

After running this command I was back to normal.

Solution 16 - Git

Run git fetch --all before git pull. That should solve the problem.

Solution 17 - Git

I had a typical Mac related issue that I could not resolve with the other suggested answers.

Mac's default file system setting is that it is case insensitive.

In my case, a colleague obviously forgot to create a uppercase letter for a branch i.e.

testBranch/ID-1 vs. testbranch/ID-2

for the Mac file system (yeah, it can be configured differently) these two branches are the same and in this case, you only get one of the two folders. And for the remaining folder you get an error.

In my case, removing the sub-folder in question in .git/logs/ref/remotes/origin resolved the problem, as the branch in question has already been merged back.

Solution 18 - Git

As a reference for Visual Studio Code (vscode, code) (and possibly other IDEs)

I had to do command: Git: Fetch (Prune)

Command line alternative should be: git fetch --prune

Then restart the whole IDE.

And to give some perspective I will quote BitBucket's docks:

> # What’s the Difference Between Git Prune,
Git Fetch --prune, and Git Remote Prune? > git remote prune and git fetch --prune do the same thing: delete the refs to branches that don't exist on the remote. This is highly desirable when working in a team workflow in which remote branches are deleted after merge to main. The second command, git fetch --prune will connect to the remote and fetch the latest remote state before pruning. It is essentially a combination of commands: >
git fetch --all && git remote prune >
The generic git prune command is entirely different. As discussed in the overview section, git prune will delete locally detached commits.

Solution 19 - Git

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

Solution 20 - Git

I had this problem, when I was trying to create a new feature branch that contained name of the old branch, e.g. origin - branch1 and I wanted to create branch1-feature. It wasn't possibble, but branch1/feature was already.

Solution 21 - Git

Aside from the many answers already supplied to this question, a simple check on the local repo branches that exist in your machine and those that don't in the remote, will help. In which case you don't use the

> git prune

command as many have suggested.

Simply delete the local branch

git branch -d <branch name without a remote tracking branch by the same name>

as shown in the attached screenshot using -D to force delete when you are sure that a local branch does not have a remote branch tracked.

lock ref error git

Solution 22 - Git

I had the same error message, root cause was a rewrite of the history (branch renaming).

That worked for me:

git remote prune origin

Source: https://codedaily.in/git-error-cannot-lock-refs/

Solution 23 - Git

Case 1: Let check branches from git-server if they are duplicated or not.

Example: two branches below are duplicated:

    - upper_with_lower
    - UPPER_with_lower

---> Let consider removing one of them.

Case 2: The branch you are pushing are duplicated with other branch.

Solution 24 - Git

In my case, it was connected with the branch name that I had already created.

To fix the issue I've created a branch with the name that for certain shouldn't exist, like:

git checkout -b some_unknown_branch

Then I've cleared all my other branches(not active) because they were just unnecessary garbage.

git branch | grep -v \* | grep -v master | xargs git branch -D

and then renamed my current branch with the name that I've intended, like:

git checkout -m my_desired_branch_name

Solution 25 - Git

In my case I had to manually delete old tags which had been removed on remote.

Solution 26 - Git

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.

Solution 27 - Git

I saw this error when trying to run git filter-branch to detach many subdirectories into a new, separate repository (as in this answer).

I tried all of the above solutions and none of them worked. Eventually, I decided I didn't need to preserve my tags all that badly in the new branch and just ran:

git remote remove origin
git tag | xargs git tag -d
git gc --prune=now
git filter-branch --index-filter 'git rm --cached -qr --ignore-unmatch -- . && git reset -q $GIT_COMMIT -- apps/AAA/ libs/xxx' --prune-empty -- --all

Solution 28 - Git

For me it was happening when I try to create a new branch with a name like this one:

master/pre-upgrade

changing it to another name like:

pre-upgrade/master

did the trick!

Solution 29 - Git

This error was coming on doing

git fetch

but in my case I just wanted the update of the main branch which can be done using

git fetch origin main

Not a solution to lock ref problem but it helped me avoid the problem :P

Solution 30 - Git

If you are in the fortunate position of having no local work to commit/push and time to get coffee, you could simply delete your local copy of the repo and re-clone

Solution 31 - Git

I got this issue when I tried to create a branch that starts with a current branch. I had a branch named develop and I tried to create a branch called develop/myFeature.

Solution 32 - Git

I had a similar issue that totally confused me. I had a local branch named test and was trying to fetch and checkout remote branch named test/some-changes.

Fix was just to remove a stale test branch, and I could fetch and checkout the remote one.

Solution 33 - Git

for me, removing .git/info/ref kick things going.There shouldn't be a ref file when git is not running. But in my case there were one for whatever reason and caused the problem.

Removing the file will not remove any of your local commits or branches.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnnDView Question on Stackoverflow
Solution 1 - Gitarno_vView Answer on Stackoverflow
Solution 2 - Gitkiran.gilvazView Answer on Stackoverflow
Solution 3 - GitjohnnyclemView Answer on Stackoverflow
Solution 4 - GitaliibrahimView Answer on Stackoverflow
Solution 5 - Gitakansh tayalView Answer on Stackoverflow
Solution 6 - GitemircView Answer on Stackoverflow
Solution 7 - GitFrankMonzaView Answer on Stackoverflow
Solution 8 - GitDharmesh MansataView Answer on Stackoverflow
Solution 9 - GitGeorge ArmstrongView Answer on Stackoverflow
Solution 10 - GitWolfTailView Answer on Stackoverflow
Solution 11 - GitJoshView Answer on Stackoverflow
Solution 12 - GitschmunkView Answer on Stackoverflow
Solution 13 - GitCodingYourLifeView Answer on Stackoverflow
Solution 14 - GitralphtheninjaView Answer on Stackoverflow
Solution 15 - GitColinView Answer on Stackoverflow
Solution 16 - GitttfreemanView Answer on Stackoverflow
Solution 17 - GitDenisView Answer on Stackoverflow
Solution 18 - Gitjave.webView Answer on Stackoverflow
Solution 19 - GitIvan DanilovView Answer on Stackoverflow
Solution 20 - Gituser11464384View Answer on Stackoverflow
Solution 21 - Gituser2347763View Answer on Stackoverflow
Solution 22 - GitMarc WäckerlinView Answer on Stackoverflow
Solution 23 - GitalphaplusView Answer on Stackoverflow
Solution 24 - GitArsen KhachaturyanView Answer on Stackoverflow
Solution 25 - GitjoliejulyView Answer on Stackoverflow
Solution 26 - GitymanView Answer on Stackoverflow
Solution 27 - GittessafyiView Answer on Stackoverflow
Solution 28 - GitOmar DulaimiView Answer on Stackoverflow
Solution 29 - GitVihaan VermaView Answer on Stackoverflow
Solution 30 - Gitandrew pateView Answer on Stackoverflow
Solution 31 - GitScottyBladesView Answer on Stackoverflow
Solution 32 - GitequiView Answer on Stackoverflow
Solution 33 - GithuangzonghaoView Answer on Stackoverflow