Problem
Windows users can often have this problem
git pull
gives the error: error: cannot lock ref
unable to update local ref
Cause
Cause a) There are multiple branches, whose
names from the beginning up to any slash (or to the end), differ only in upper and lower case.
Branch name clashing (upper/lower case)
#######################################
# Example 1)
#############################
feature/releasecandidate/fix123
feature/releaseCandidate/improveFeature789
------------------------
^
Identical from beginning up to a slash (here the 2nd one)
except for the marked letter, where the upper/lower case differs
# Example 2)
#############################
releaseBranch
releasebranch
-------------
^
Identical from beginning to the end
except for the marked letter
Cause b) Also a problem on linux: One branch is a prefix of another, with a slash boundary:
Prefix with slash-boundary
#######################################
# Example 1) - also a problem on linux
#############################
feature/release2021
feature/release2021/fixIssue07
^
slash boundary
# Example 2)
#############################
feature/release2022
feature/Release2022/fixIssue99
^ ^
differing case slash boundary
(problem on
windows)
Solution
Remove the cause (see exact Cause above).
# inspect your branches, to see if you have the upper/lower case problem
git ls-remote --heads YOUR-GIT-URL
For example: create a branch-naming policy, e.g. all in lower-case letters; or letters before the last slash in lower-case. Or some smart hook, that detect a violation. (but note: In cause a) the problem is only on windows, not on linux).
Background
The problem is that windows stores these branches (from example 1 and 2) in the .git
folder
# inspect the files/folders under
.git/refs/remotes/origin/
and in Cause a) windows cannot distinguish
the differences in upper/lower case, so git on window goes crazy.
In Cause b) you cannot have a folder (e.g. feature/release2021/
) with the same name as a file (feature/release2021
).
Workaround
A short-term workaround that often works (until you’ve removed the cause) is:
git pack-refs --all
# delete the contents of .git/refs/remotes/origin/*
rm -rf .git/refs/remotes/origin/*
git pull; git pull; git pull # all good? yes!
Do you want to understand what «error: cannot lock ref» in Git actually means and how to fix it?
Version control (VCS) has become a vital part of modern software development workflow. Many VCS system exists, but market research shows that Git is the most popular of all.
Before Git you would copy the entire repository to another directory and then by hand copy your changes to the correct repository. Now creating a branch takes about as long as it takes to type the command. Git scratched many itches, some of which we didn’t even realize until we know it.
Most of the time, Git handles most changes automatically and encourages users to integrate the changes every day or even more often. But sometimes, Git can pops out strange error which is pretty vague and hard to debug if you’re a beginner.
This article is going to show you the reason behind «error: cannot lock ref» in Git and how to fix the error quickly.
Understanding Git locking mechanism
In order to understand why the reason behind «error: cannot lock ref», first, you need to know how Git uses a locking mechanism internally.
Everything related to your working directory is placed in a single, hidden directory named .git
. Inside .git
is all kinds of information about branch, commit, submodule, etc.
A typical .git
directory looks like this
.git/
hooks/
info/
logs/
objects/
refs/
HEAD
config
description
index
packed-refs
Look closer into /refs
and you will see /heads
and /tags
inside. They are the directories that contains information about each of your file in branches and tags.
Whenever you run an operation in Git, it creates index.lock
file inside .git
directory to ensure that no other Git process takes place during the operation.
«error: cannot lock ref» simply means information in /refs
are corrupted and Git cannot continue to create index.lock
file.
What the error looks like
«error: cannot lock ref» comes in many forms, often followed by addition information about what gone wrong. Below is a few of the outputs we’ve seen :
C:MyWorkStuffProjectsRubyMyProject>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
> git pull
error: cannot lock ref 'refs/tags/v2.8': 'refs/tags' exists; cannot create 'refs/tags/v2.8'
From github.com:k3it/qsorder
! [new tag] v2.8 -> v2.8 (unable to update local ref)
error: cannot lock ref 'refs/tags/v2.9': 'refs/tags' exists; cannot create 'refs/tags/v2.9'
! [new tag] v2.9 -> v2.9 (unable to update local ref)
error: cannot lock ref 'refs/remotes/origin/test': is at c21593dc62042d39efc044f366579667e but expected 3d0e5b15fc558cd447fb475a8ecd999
> git pull origin master
From github.com:Microsoft/vscode
* branch master -> FETCH_HEAD
error: cannot lock ref 'refs/remotes/origin/master': is at 2e4bfdb24fd137a1d2e87bd480f283cf7001f19a but expected 70ea06a46fd4b38bdba9ab1d64f3fee0f63806a5
! 70ea06a46f..2e4bfdb24f master -> origin/master (unable to update local ref)
Now let’s go through possible solutions to make the «error: cannot lock ref» goes away.
Quick fix : Remove and re-add remote
As all general computer-related advice said : When in doubt, restart! The quickest way you can get rid of «error: cannot lock ref» is to remove the remote so that you can add it again later.
If you don’t know how to do that, follow step-by-step instructions below.
-
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]:your-username/repo-name.git (fetch)
origin [email protected]:your-username/repo-name.git (push)
-
Remove the remote from your local git repo:
git remote rm origin
-
Add the remote back to your local repo:
git remote add origin [email protected]:your-username/repo-name.git
Prune remote origin
Users across online forums have reported that the command below worked for them:
git remote prune origin
The command will 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.
If you’re reluctant to try the command above, which I didn’t at first, you can run git remote prune origin --dry-run
to see what happens before proceeding with the actual command.
Clean up and optimize local repository
Git has a built-in gc
command to cleanup unnecessary files and optimize the local repository. The command do housekeeping tasks such as compressing file revisions to improve performance, removing unreachable objects which may have been created from prior invocations of git add, packing refs, pruning reflog, rerere metadata or stale working trees.
Run the following command to optimize your current repository.
git gc --prune=now
If it didn’t work, you can remove .git/logs/refs/remotes/origin/branch
and .git/refs/remotes/origin/branch
then try again, as a few users reported that it works for them.
Double check for confusing branch names
If you’re creating a new branch and none of the above solutions works for you, the next thing you can do is to verify that your existing branch names don’t conflict with the new one. In Git, once a branch named a
already exists, you cannot create a/b
. Likewise, if a/b
exists, creating a/b/c
branch is not possible.
Содержание
- “error: cannot lock ref” – what to do?
- Understanding Git locking mechanism
- What the error looks like
- Quick fix : Remove and re-add remote
- Prune remote origin
- Clean up and optimize local repository
- Double check for confusing branch names
- Git “error: cannot lock ref” error
- What causes this error
- Check if there are two branches that have the same name
- Update local repository
- Error: Cannot lock ref ‘refs/remotes/origin/master’ #6121
- Comments
- Description
- Version
- Steps to Reproduce
- Expected(Blue Box) and Actual(Red Box) Behavior
- Additional Information
- reference broken #3838
- Comments
“error: cannot lock ref” – what to do?
Do you want to understand what «error: cannot lock ref» in Git actually means and how to fix it?
Version control (VCS) has become a vital part of modern software development workflow. Many VCS system exists, but market research shows that Git is the most popular of all.
Before Git you would copy the entire repository to another directory and then by hand copy your changes to the correct repository. Now creating a branch takes about as long as it takes to type the command. Git scratched many itches, some of which we didn’t even realize until we know it.
Most of the time, Git handles most changes automatically and encourages users to integrate the changes every day or even more often. But sometimes, Git can pops out strange error which is pretty vague and hard to debug if you’re a beginner.
This article is going to show you the reason behind «error: cannot lock ref» in Git and how to fix the error quickly.
Understanding Git locking mechanism
In order to understand why the reason behind «error: cannot lock ref», first, you need to know how Git uses a locking mechanism internally.
Everything related to your working directory is placed in a single, hidden directory named .git . Inside .git is all kinds of information about branch, commit, submodule, etc.
A typical .git directory looks like this
Look closer into /refs and you will see /heads and /tags inside. They are the directories that contains information about each of your file in branches and tags.
Whenever you run an operation in Git, it creates index.lock file inside .git directory to ensure that no other Git process takes place during the operation.
«error: cannot lock ref» simply means information in /refs are corrupted and Git cannot continue to create index.lock file.
What the error looks like
«error: cannot lock ref» comes in many forms, often followed by addition information about what gone wrong. Below is a few of the outputs we’ve seen :
Now let’s go through possible solutions to make the «error: cannot lock ref» goes away.
Quick fix : Remove and re-add remote
As all general computer-related advice said : When in doubt, restart! The quickest way you can get rid of «error: cannot lock ref» is to remove the remote so that you can add it again later.
If you don’t know how to do that, follow step-by-step instructions below.
Copy the SSH git URL of your existing remote. You can print it to the terminal using this command:
which will print out something like this:
Remove the remote from your local git repo:
git remote rm origin
Add the remote back to your local repo:
git remote add origin [email protected]:your-username/repo-name.git
Prune remote origin
Users across online forums have reported that the command below worked for them:
The command will 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.
If you’re reluctant to try the command above, which I didn’t at first, you can run git remote prune origin —dry-run to see what happens before proceeding with the actual command.
Clean up and optimize local repository
Git has a built-in gc command to cleanup unnecessary files and optimize the local repository. The command do housekeeping tasks such as compressing file revisions to improve performance, removing unreachable objects which may have been created from prior invocations of git add, packing refs, pruning reflog, rerere metadata or stale working trees.
Run the following command to optimize your current repository.
If it didn’t work, you can remove .git/logs/refs/remotes/origin/branch and .git/refs/remotes/origin/branch then try again, as a few users reported that it works for them.
Double check for confusing branch names
If you’re creating a new branch and none of the above solutions works for you, the next thing you can do is to verify that your existing branch names don’t conflict with the new one. In Git, once a branch named a already exists, you cannot create a/b . Likewise, if a/b exists, creating a/b/c branch is not possible.
Источник
Git “error: cannot lock ref” error
The following error occurred in my environment when I executed git pull .
What causes this error
If a branch name includes a slash, Git tries to create a folder. For example, if the branch name is bugfix/branch-name1, we can find the file your-directory/.git/refs/remotes/origin/bugfix/branch-name1.
I’ve not tested it but I guess if we create another branch Bugfix/branch-name2, we can find the file your-directory/.git/refs/remotes/origin/bugfix/branch-name2. The second branch name starts with an upper case while the first one is the lower case but Git can create the file because the file name is different.
However, if there are bugfix/branch-name1 and Bugfix/branch-name1 in the repository, Git throws this error . It seems that Git is case-sensitive but Windows is not. It’s impossible to create two folders that have the same name but different cases like bugfix and BUGFIX .
bugfix/branch-name1/branch1 causes this error if bugfix/branch-name1 has already existed.
Check if there are two branches that have the same name
Check if there are two branches that have the same name with this command.
If the branch is found, remove one of them or rename them.
Update local repository
Once the branch is removed, we need to update the local repository. Otherwise, the branch still remains in our repository. We need to remove branches that are no longer in the remote repository. Execute the following command. It removes all branches from the local repository that have gone from the remote repository.
Try to execute git pull or git fetch . It should work now.
If you want to learn the most used Git commands, check this post.
Источник
Error: Cannot lock ref ‘refs/remotes/origin/master’ #6121
I have some problem with my GitHub. I read similar questions and answers to them in many forums, but unfortunately nothing helped.
error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference
‘refs/remotes/origin/master’: reference broken
From https://github.com/arbuzzer/arbuzzer.github.io
! [new branch] master -> origin/master (unable to update local ref)
The text was updated successfully, but these errors were encountered:
Hi @arbuzzer, thanks for the report and sorry you’re having issues.
We ask that folks fill out the template so we can better understand your setup and what’s going on so we make the best use of the maintainers’ time. Here’s the template you need: https://github.com/desktop/desktop/issues/new?template=bug_report.md
Thanks for understanding and meeting us halfway! 😄
@arbuzzer It looks like there may be some underlying repository corruption that is causing this issue. Could you go to the file menu in GitHub Desktop and select Repository > Open in and run the command git fsck ? That should give some some more information about this error. Please share the full output of that command.
@arbuzzer It looks like there may be some underlying repository corruption that is causing this issue. Could you go to the file menu in GitHub Desktop and select Repository > Open in and run the command git fsck ? That should give some some more information about this error. Please share the full output of that command.
Hi @arbuzzer, thanks for the report and sorry you’re having issues.
We ask that folks fill out the template so we can better understand your setup and what’s going on so we make the best use of the maintainers’ time. Here’s the template you need: https://github.com/desktop/desktop/issues/new?template=bug_report.md
Thanks for understanding and meeting us halfway! 😄
Description
error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference
‘refs/remotes/origin/master’: reference broken
From https://github.com/arbuzzer/arbuzzer.github.io
! [new branch] master -> origin/master (unable to update local ref)
Version
*GitHub Desktop:
*Operating system:
Steps to Reproduce
- I read the whole topic on this site and none of the proposed solutions helped me. (https://stackoverflow.com/questions/2998832/git-pull-fails-unable-to-resolve-reference-unable-to-update-local-ref)
Expected(Blue Box) and Actual(Red Box) Behavior
3.
And so with every command that people offer.
Additional Information
Thanks for sharing that information @arbuzzer. A few other questions:
- Based on the screenshot it looks like you are were running those commands in your root directory (i.e. C:UsersYour_User) — is that the correct location of this repository, or is it possibly in a different directory? If you are storing this repository in a different location you will need to run Git commands from within that directory that contains your repository.
- Is this a repository that you just freshly cloned to your local machine using GitHub Desktop?
It would also be helpful if you could run the following two commands within the repository directory to provide more configuration information about your local repository:
git branch -a
git config -l —list
Please let me know the output of both of those commands
Thanks for sharing that information @arbuzzer. A few other questions:
- Based on the screenshot it looks like you are were running those commands in your root directory (i.e. C:UsersYour_User) — is that the correct location of this repository, or is it possibly in a different directory? If you are storing this repository in a different location you will need to run Git commands from within that directory that contains your repository.
- Is this a repository that you just freshly cloned to your local machine using GitHub Desktop?
It would also be helpful if you could run the following two commands within the repository directory to provide more configuration information about your local repository:
git branch -a
git config -l —list
Please let me know the output of both of those commands
Thanks for sharing that information @arbuzzer. A few other questions:
- Based on the screenshot it looks like you are were running those commands in your root directory (i.e. C:UsersYour_User) — is that the correct location of this repository, or is it possibly in a different directory? If you are storing this repository in a different location you will need to run Git commands from within that directory that contains your repository.
- Is this a repository that you just freshly cloned to your local machine using GitHub Desktop?
It would also be helpful if you could run the following two commands within the repository directory to provide more configuration information about your local repository:
git branch -a
git config -l —list
Please let me know the output of both of those commands
I did all the actions described on the forums again and that’s what I did. Expected(Blue Box) and Actual(Red Box) Behavior.
Источник
reference broken #3838
error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference ‘refs/remotes/origin/master’: reference broken
From https://github.com/herio5154/stargoon
! [new branch] master -> origin/master (unable to update local ref)
The text was updated successfully, but these errors were encountered:
@herio5154 thanks for the feedback! It looks like something with the underlying Git repository has broken, leaving it in an invalid state.
I think these steps should get you back to a happy place, but take a backup of your repository before running any of these commands, just in case.
I’ll explain the intent behind each step as we go along. This assumes using Git Bash, but if you are using a different shell let me know which and I’ll tweak it.
Git stores refs and other Git data on disk under the .git folder, and it looks like the value of whatever origin/master entry Git was tracking is now invalid. This will remove the file to hide it from Git locally.
This tells Git to go and fetch whatever it can find from the remote.
This ensures your local master is tracking whatever is currently on origin/master , which should put Git back into a happy place.
Closing this out due to inactivity. @herio5154 let us know if there’s anything else we can do to address the problem!
This actually worked for me too, thanks! ❤️
This worked for me too
Hello,
I’m having the same problem in GitHub Desktop, but I’m fairly new to using it and don’t have Git installed, only GitHub Desktop. Could you explain how to approach solving the problem assuming a little bit less pre-existing knowledge & without having Git installed? I’m working on Windows 10 and have the latest version of GitHub Desktop.
Thank you!
@cfandel are you seeing the same exact error output? If you can share the specific error message I can verify that the solution provided will work for you.
Could you explain how to approach solving the problem assuming a little bit less pre-existing knowledge & without having Git installed?
Unfortunately this problem is not resolvable within GitHub Desktop since it requires running a few specific Git commands. Since you do not have Git installed, you will need to download it from here:
Once you install Git you can launch it directly from GitHub Desktop and follow the steps @shiftkey provided. I would recommend making a backup of the repository, and let me know if you run into any specific issues.
The other workaround would be to clone a fresh copy of the repository, which will not have the broken references. If your local repository and remote repository are up-to-date with each other then that would be the easiest solution.
Thanks for the quick response!
The files on my computer (these are called the local files yes?) are up to date, but the files on GitHub are NOT up to date (because I made changes locally and then wasn’t able to push them).
In GitHub Desktop, the push button has changed to ‘Publish branch’ and I get the following error:
error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference ‘refs/remotes/origin/master’: reference broken From https://github.com/cfandel/gottesacker ! [new branch] master -> origin/master (unable to update local ref)
I downloaded Git and tried the steps above, but get this result:
$ rm.git/refs/remotes/origin/master bash: rm.git/refs/remotes/origin/master: No such file or directory
When you say clone a fresh copy of the repository, does that mean taking the copy on my computer and replacing everything currently on GitHub with the files I have, or vice-versa? If it means preserving the version on my computer, that’s a fine solution, but otherwise it will result in losing a bunch of work.
Also, in the long term, if this issue happens again, it would be best to know how to repair it without having to clone a fresh copy no?
**Note: I wasn’t able to see where to launch Git from GitHub Desktop? So I tried this in Git Bash launched from the Windows Search Bar.
@cfandel it looks like you may have missed a space between the rm (remove) command and the file path:
**Note: I wasn’t able to see where to launch Git from GitHub Desktop? So I tried this in Git Bash launched from the Windows Search Bar.
You can go to the menu and select File > Open in Command Prompt . That will launch CMD — if you would prefer to use Git Bash you can change this setting by going to File > Options > Advanced and choosing Git Bash from the Shell dropdown.
If it means preserving the version on my computer, that’s a fine solution, but otherwise it will result in losing a bunch of work.
In that case we will want to get things working with the local repository, since a fresh clone will not have your local changes.
@cfandel it may actually be that you were not in the correct directory when you ran the command — if you open the repository in the command line from within GitHub Desktop it will drop you right into the correct directory. If you open Git Bash separately it will launch into your User directory, and you will need to use cd /path/to/repository to change to the correct directory.
Thanks so much for the help!
I opened Command Prompt from GitHub Desktop (though it’s under the Repository menu not the File menu), and tried again. If I understand correctly, all Git commands run from Command Prompt have to be preceded by the word «git»? And if they are run from Git Bash, the command is exactly the same but without the preceding «git», but I need to make sure to be in the correct directory first?
Unfortunately I’m still not having any success with the steps above.
Here are the commands I tried and the results (note that I am now in the correct directory I think):
C:UsersChloeDocumentsGitHubgottesacker>rm .git/refs/remotes/origin/master
‘rm’ is not recognized as an internal or external command, operable program or batch file.
This means I need to tell Command Prompt that I want to use Git commands right?
So I tried adding a preceding «git»:
C:UsersChloeDocumentsGitHubgottesacker>git rm .git/refs/remotes/origin/master
And get this result:
fatal: pathspec ‘.git/refs/remotes/origin/master’ did not match any files
If I try skipping to the next step I get this:
C:UsersChloeDocumentsGitHubgottesacker>git fetch error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference ‘refs/remotes/origin/master’: reference broken From https://github.com/cfandel/gottesacker ! [new branch] master -> origin/master (unable to update local ref)
***EDIT:
I tried this exact same process, but by opening Git Bash from within GitHub Desktop, and it seems to have worked! However, I’m still not at all clear about why — what is the difference between doing it in Command Prompt and doing it in Git Bash?
@cfandel I’m glad you were able to workaround the issue!
‘rm’ is not recognized as an internal or external command, operable program or batch file.
This means I need to tell Command Prompt that I want to use Git commands right?
rm is a built-in program that’s part of most Unix shells. The equivalent command in Command Prompt is del but they accept different parameters, so be mindful of the shell you are using to run commands.
However, I’m still not at all clear about why — what is the difference between doing it in Command Prompt and doing it in Git Bash?
Git Bash has an rm included in it’s environment, so the command works fine there. git rm is a Git-specific command to remove files from within a Git repository, and isn’t a replacement for rm .
Источник
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
arbuzzer opened this issue
Nov 7, 2018
· 31 comments
· Fixed by #6141
Assignees
Comments
I have some problem with my GitHub. I read similar questions and answers to them in many forums, but unfortunately nothing helped.
error: cannot lock ref ‘refs/remotes/origin/master’: unable to resolve reference
‘refs/remotes/origin/master’: reference broken
From https://github.com/arbuzzer/arbuzzer.github.io
! [new branch] master -> origin/master (unable to update local ref)
arbuzzer
changed the title
Error: Cannot lock ref …
Error: Cannot lock ref ‘refs/remotes/origin/master’
Nov 7, 2018
@arbuzzer It looks like there may be some underlying repository corruption that is causing this issue. Could you go to the file menu in GitHub Desktop and select Repository
> Open in <your_default_command_line_application>
and run the command git fsck
? That should give some some more information about this error. Please share the full output of that command.
@arbuzzer It looks like there may be some underlying repository corruption that is causing this issue. Could you go to the file menu in GitHub Desktop and select
Repository
>Open in <your_default_command_line_application>
and run the commandgit fsck
? That should give some some more information about this error. Please share the full output of that command.
Thanks for sharing that information @arbuzzer. A few other questions:
- Based on the screenshot it looks like you are were running those commands in your root directory (i.e. C:UsersYour_User) — is that the correct location of this repository, or is it possibly in a different directory? If you are storing this repository in a different location you will need to run Git commands from within that directory that contains your repository.
- Is this a repository that you just freshly cloned to your local machine using GitHub Desktop?
It would also be helpful if you could run the following two commands within the repository directory to provide more configuration information about your local repository:
git branch -a
git config -l --list
Please let me know the output of both of those commands
Thanks for sharing that information @arbuzzer. A few other questions:
- Based on the screenshot it looks like you are were running those commands in your root directory (i.e. C:UsersYour_User) — is that the correct location of this repository, or is it possibly in a different directory? If you are storing this repository in a different location you will need to run Git commands from within that directory that contains your repository.
- Is this a repository that you just freshly cloned to your local machine using GitHub Desktop?
It would also be helpful if you could run the following two commands within the repository directory to provide more configuration information about your local repository:
git branch -a
git config -l --list
Please let me know the output of both of those commands
Thanks for sharing that information @arbuzzer. A few other questions:
- Based on the screenshot it looks like you are were running those commands in your root directory (i.e. C:UsersYour_User) — is that the correct location of this repository, or is it possibly in a different directory? If you are storing this repository in a different location you will need to run Git commands from within that directory that contains your repository.
- Is this a repository that you just freshly cloned to your local machine using GitHub Desktop?
It would also be helpful if you could run the following two commands within the repository directory to provide more configuration information about your local repository:
git branch -a
git config -l --list
Please let me know the output of both of those commands
I did all the actions described on the forums again and that’s what I did. Expected(Blue Box) and Actual(Red Box) Behavior.
Thanks @arbuzzer. Try running the command git fetch --all
to grab the remote origin/master
branch again. That should hopefully fix this issue.
Спасибо @arbuzzer . Попробуйте запустить команду,
git fetch --all
чтобыorigin/master
снова захватить удаленную ветку. Это, надо надеяться, исправить эту проблему.
Thanks @arbuzzer. Try running the command
git fetch --all
to grab the remoteorigin/master
branch again. That should hopefully fix this issue.
Maybe it will help me to reinstall the system, or is it easier for me to create a new account? It is just important for me to use this application.
@arbuzzer apologies — I think we need to clean things up before running that command. Try these steps:
rm .git/refs/remotes/origin/master
git fetch
git branch --set-upstream-to=origin/master
Let me know if that doesn’t get things working.
mkkmail, CH0918, and ThorstenHans reacted with hooray emoji
FrancisNgn, vicky-gonsalves, briancalma, richierich25, ankitdangayach, alaxmi14, hadarkam, zuercher8353, vladossuper, markcarcillar, and 4 more reacted with heart emoji
@arbuzzer apologies — I think we need to clean things up before running that command. Try these steps:
rm .git/refs/remotes/origin/master
git fetch
git branch --set-upstream-to=origin/master
Let me know if that doesn’t get things working.
It doesn’t work
@arbuzzer sorry about that — you will need to run del .git/refs/remotes/origin/master
since you are using the command prompt.
Maybe it will help me to reinstall the system, or is it easier for me to create a new account? It is just important for me to use this application.
If you would like you can also perform a fresh clone of the repository to GitHub Desktop — a fresh clone will not have the issues you are encountering.
Repository fixes aside, I think #6141 here should prevent us from ending up in this situation again
@arbuzzer сожалеет об этом — вам нужно будет запускать
del .git/refs/remotes/origin/master
с тех пор, как вы используете командную строку.Может быть, это поможет мне переустановить систему, или мне легче создать новую учетную запись? Для меня просто важно использовать это приложение.
Если вы хотите, чтобы вы также могли использовать новый клон репозитория для GitHub Desktop — новый клон не будет иметь проблем, с которыми вы сталкиваетесь.
Sorry for the delay in getting back to you @arbuzzer. I’m not sure why the refs
directory would not exist unless it was deleted. If you navigate to the GitHubarbuzzer.github.io.gitrefs
in File Explorer do you see anything there?
Closing this out due to inactivity.
@arbuzzer if you’re able to answer @steveward’s question in the previous comment we’re happy to revisit it.
nice!this solved my problem
This worked for me :
git remote prune origin
Miko2x, AnnaGerasim0va, markerberg, VitorLuizC, kevinstategami, HarrisonGrodin, aliuwahab, and ratneshnavlakhe reacted with hooray emoji
git remote prune origin
This worked for me too!
Try
$ git gc --prune=now
$ git remote prune origin
cleaning-up your local repository with:
After searching constantly, this is the solution that worked for me which entails unsetting/removing the Upstream
git branch --unset-upstream
git branch —set-upstream-to=origin/master
It worked like a charm! Thanks
rm .git/refs/remotes/origin/master
git fetch
git branch —set-upstream-to=origin/master
—> This worked for me magically.
git fetch —all
git branch —set-upstream-to=origin/master
/* This one works for me */
thanks a lot.
rm .git/refs/remotes/origin/master
git fetch
git branch —set-upstream-to=origin/master—> This worked for me magically.
@richierich25 worked for me too
thanks
I had a similar issue running VSCode on Windows 10 and trying to commit changes or push. However what solved it for me was changing my controlled folder access in Windows settings which was preventing git from creating the .lock files locally.
@arbuzzer apologies — I think we need to clean things up before running that command. Try these steps:
rm .git/refs/remotes/origin/master
git fetch
git branch --set-upstream-to=origin/master
Let me know if that doesn’t get things working.
This worked for me. Thanks!
None of the previous methods worked for me, so what I did was make a copy of the folder, delete the folder, go to GitHub Desktop, clone the repository, paste the files that I had modified that I couldn’t upload and that’s it.
@arbuzzer apologies — I think we need to clean things up before running that command. Try these steps:
rm .git/refs/remotes/origin/master
git fetch
git branch --set-upstream-to=origin/master
Let me know if that doesn’t get things working.
thank you
@arbuzzer道歉——我认为我们需要在运行该命令之前清理一下。尝试以下步骤:
rm .git/refs/remotes/origin/master
git fetch
`git branch —set-upstream-to=origin/maste
谢谢你
Using git 1.6.4.2, when I tried a git pull
I get this error:
error: unable to resolve reference refs/remotes/origin/LT558-optimize-sql: No such file or directory
From git+ssh://remoteserver/~/misk5
! [new branch] LT558-optimize-sql -> origin/LT558-optimize-sql (unable to update local ref)
error: unable to resolve reference refs/remotes/origin/split-css: No such file or directory
! [new branch] split-css -> origin/split-css (unable to update local ref)
I’ve tried git remote prune origin
, but it didn’t help.
30 Answers
Try cleaning-up your local repository with:
$ git gc --prune=now
$ git remote prune origin
man git-gc(1):
git-gc - Cleanup unnecessary files and optimize the local repository
git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]
Runs a number of housekeeping tasks within the current repository, such as compressing file revisions
(to reduce disk space and increase performance) and removing unreachable objects which may have been
created from prior invocations of git add.
Users are encouraged to run this task on a regular basis within each repository to maintain good disk
space utilization and good operating performance.
man git-remote(1):
git-remote - manage set of tracked repositories
git remote prune [-n | --dry-run] <name>
Deletes all stale remote-tracking branches under <name>. These stale branches have already been
removed from the remote repository referenced by <name>, but are still locally available in
"remotes/<name>".
Happened to me as well. In my case, the bad ref was master, and I did the following:
rm .git/refs/remotes/origin/master
git fetch
This made git restore the ref file. After that everything worked as expected again.
This did the job for me:
git gc --prune=now
For me, it worked to remove the files that are throwing errors from the folder .git/refs/remotes/origin/
.
Try it:
git gc --prune=now
git remote prune origin
git pull
I just would like to add one of the possible causes of a broken Git reference.
Possible root cause
On my system (Windows 7 64-bit), when a BSOD happens, some of the stored reference files (most likely currently opened/being written into when the BSOD happened) are overwritten with NULL
characters (ASCII 0).
As others mentioned, to fix it, it’s enough to just delete those invalid reference files and re-fetch or re-pull the repository.
Example
Error message:
cannot lock ref ‘refs/remotes/origin/some/branch’: unable to resolve reference ‘refs/remotes/origin/some/branch’: reference broken
Solution:
Delete the reference refs/remotes/origin/some/branch
which is stored in the file %repo_root%/.git/refs/remotes/origin/some/branch
.
Explanation: It appears your remote repo (in Github / bitbucket) branches were removed ,though your local references were not updated and pointing to non existent references.
In order to solve this issue:
git fetch --prune
git fetch --all
git pull
For extra reading — Reference from Github documentation :
git-fetch — Download objects and refs from another repository
—all
Fetch all remotes.—prune After fetching, remove any remote tracking branches which no longer exist on the remote.
Execute the following commands:
rm .git/refs/remotes/origin/master
git fetch
git branch --set-upstream-to=origin/master
Just in case, if you need to know what is
.git/refs/remotes/origin/master
, you would read the Remotes section
in Git References.
I had this same issue and solved it by going to the file it was erroring on:
repo.gitrefsremotesoriginmaster
This file was full of nulls, I replaced it with the latest ref from github.
In my case, the problem was solved after I’ve deleted all the remove reference files under the directory .git
.
If you look at the message, it would tell you which files you need to delete (specifically).
The files to delete sit under .git/refs/remotes
.
I’ve just deleted all the files there, and ran gc prune
git gc --prune=now
After that, everything works just fine.
git fetch --prune
fixed this error for me:
[[email protected]] - [~/code/driving] - [Wed May 10, 02:58:25]
[I]> git fetch
error: cannot lock ref 'refs/remotes/origin/user/janek/integration/20170505': 'refs/remotes/origin/user/janek/integration' exists; cannot create 'refs/remotes/origin/user/janek/integration/20170505'
From github.com:zooxco/driving
! [new branch] user/janek/integration/20170505 -> origin/user/janek/integration/20170505 (unable to update local ref)
From github.com:zooxco/driving
[[email protected]] - [~/code/driving] - [Wed May 10, 02:58:30]
[I]> git fetch --prune
- [deleted] (none) -> origin/user/janek/integration
This assumes that the offending branch was deleted on the remote, though.
You can also add this to ~/.gitconfig
to automatically prune when running git fetch
:
[fetch]
prune = true
If this error “unable to update local ref” is reoccurring, even after applying either the answer by Vojtech Vitek or Michel Krämer you may you may have a bad ref on your local AND master repository.
In this case you should apply both fix’s without pulling or pushing in between …
rm .git/refs/remotes/origin/master
git fetch
git gc --prune=now
git remote prune origin
A permanent resolution for me was only achieved after applying both fix’s before push/pull.
For me, I solved it this way:
rm .git/refs/remotes/origin/master
git fetch
After that I get this message from github.
There is no tracking information for the current branch
So next I did to fix this was:
git branch --set-upstream-to=origin/master master
git pull
To Answer this in very short, this issue comes when your local has some information about the remote and someone changes something which makes remote and your changes unsync.
I was getting this issue because someone has deleted remote branch and again created with the same name.
For dealing with such issues, do a pull or fetch from remote.
git remote prune origin
or if you are using any GUI, do a fetch from remote.
Try this:
git pull origin Branch_Name
Branch_Name
, the branch which you are currently on.
If you do only a git pull
, it pulls all other created branch name as well.
So is the reason you are getting this:
! [new branch] split-css -> origin/split-css (unable to update local ref)
I was able to work with
git remote update --prune
For me, I had a local branch named feature/phase2
and the remote branch was named feature/phase2/data-model
. The naming conflict was the cause of the problem, so I deleted my local branch (you could rename it if it had anything you needed to keep)
If git gc --prune=now
dosen’t help you. (bad luck like me)
What I did is remove the project in local, and re clone the whole project again.
I’m using Tower and for some reason my folder name was .git/refs/remotes/origin/Github
. Changing it to lowercase .git/refs/remotes/origin/github
solved the issue.
I had same issue. i follow following steps
1)switch your branch which having issue to other branch
2) delete that branch
3) checkout again.
Note:- You can stash you uncommitted changes and put it back again.
I used git prune origin
and that did the work.
Writing down a specific case that might cause this problem.
One day I pushed a branch named «feature/subfeature», while having «feature» branch on remote.
That operation worked fine without any error on my side, but when my co-workers fetched and/or pulled any branch, they all had the exact same error message unable to update local ref
, cannot lock ref 'refs/remotes/origin/feature/subfeature
.
This was solved by deleting feature
branch on remote(git push --delete origin feature
) and then running git remote prune origin
on my co-workers’ repo, which generated messages including * [pruned] origin/feature
.
So, my guess is git fetch
was trying to create subfeature
ref in feature
folder on git internally(.git/…), but creating folder failed because there was feature
ref already.
I had the same problem with composer update. But for me it only worked after I cleared the composer cache and after deleting the content of the vendor folder:
rm -rf vendor/*
git gc --prune=now
git pull
composer clear-cache
composer update my/package
Got this issue when trying to clone from a git bundle
created file, none of the other answers worked because I couldn’t clone the repo (so git gc
and removing/editing files was out of the question).
There was however another way to fix this — the source file of a .bundle
file was begining with:
# v2 git bundle
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d HEAD
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master
9a3184e2f983ba13cc7f40a820df8dd8cf20b54d refs/heads/master
PACK.......p..x...Kj.0...: (and so on...)
Simply removing the fourth line with vim fixed the issue.
I had this issue while using SourceTree. I tried to pull again and it worked. I think I Was witching branches (checkout) too fast :).
My situation is a bit different from the poster’s because my repository has been relatively cooperative, without any apparent corruption.
Had the same msg but with a directory, got a failed msg on pull.
git —prone did not help me either.
Turns out there was a file with the same name as a directory created remotely.
Had to go to .gitlogsrefsremotesorigin and erase the locale file — then pull again, all good.
# remove the reference file of the branch "lost"
rm -fv ./.git/refs/remotes/origin/feature/v1.6.9-api-token-bot-reader
# get all the branches from the master
git fetch --all
# git will "know" how-to handle the issue from now on
# From github.com:futurice/senzoit-www-server
# * [new branch] feature/v1.6.9-api-token-bot-reader ->
# origin/feature/v1.6.9-api-token-bot-reader
# and push your local changes
git push
Faced the same issue when repository was deleted and created with the same name. It worked only when I re-set the remote url like below;
git remote set-url origin [GIT_REPO_URL]
Verify the remote url:
git remote -v
Now, all commands should work as usual.
Just ran into the problem today.
Troubleshooting method:
With SourceTree on Windows Servers, you may try to run it as an Administrator. That fixes my problem of «unable to update local ref» on Atlassian Source Tree 2.1.2.5 on a Windows Server 2012 R2 in domain.
If you can too replicate this situation, it proves that the problem is caused by permission issue. It’s better to drill down and find the root cause — probably some particular files are owned by other users and such — otherwise there’s an unwelcome side-effect: you’ll have to run SourceTree as Administrator for the rest of eternity.
We got this issue when a developer on Mac created a branch with a greater than «>» symbol in the branch name.
That caused problems in TeamCity, and on local Windows based computers running SourceTree. BitBucket let it through without any problems.
To resolve the user removed the branch and recreated it. Which was nice and easy.