error: cannot lock ref.. 'refs/tags' exists; cannot create 'refs/tags/
GitGithubGit Problem Overview
I'm getting a strange "cannot lock ref" error when trying to pull changes from github. I've tried git gc, and looked around for similar errors but can't find a solution.
> 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)
Git Solutions
Solution 1 - Git
Your Git is complaining that a reference (rather than a directory) named refs/tags
exists. It's not clear what would create that, but see if git rev-parse refs/tags
produces a hash ID. If so, that reference needs to go away:
git update-ref -d refs/tags
after which git fetch
should work.
If git rev-parse refs/tags
fails (which it should—refs/tags
itself should not be a valid name) then this is not the problem and it's not clear what the actual problem is.
Solution 2 - Git
Running
git remote prune origin
Worked for me. Not sure why this was the issue, but seems like there was a broken reference to a remote branch.
Solution 3 - Git
> error: cannot lock ref 'refs/tags/v2.8': 'refs/tags' exists; cannot create 'refs/tags/v2.8' From github.com:k3it/qsorder
Try deleting your local tag v2.8
and v2.9
then pull again.
$ git tag -d v2.8
$ git tag -d v2.9
$ git pull
If you want to delete all local tags by a command:
$ git tag | xargs git tag -d
Solution 4 - Git
git gc
will solve it!
Cleanup unnecessary files and optimize the local repository
Link
Solution 5 - Git
In my case, the following helped:
git fetch --prune origin
git pull
Solution 6 - Git
#!/usr/bin/env bash
echo "update-ref delete refs/tags"
log="git-update-ref-errors.log"
script="./git-update-ref-exist-tags-delete.sh"
git_command="git update-ref -d refs/tags"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors to ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '\1':p" >> ${script}
echo "execute ${script}"
${script}
echo fetch
log="git-fetch-errors.log"
script="./git-fetch-exist-tags-delete.sh"
git_command="git fetch"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors from ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '\1':p" >> ${script}
echo "execute ${script}"
${script}
git fetch
echo pull
log="git-pull-errors.log"
script="./git-pull-exist-tags-delete.sh"
git_command="git pull"
echo "log errors from ${git_command} to ${log}"
${git_command} 2>&1 | > ${log}
echo "show errors from ${log}"
cat ${log}
echo create ${script}
touch ${script}
echo "add execute (+x) permissions to ${script}"
chmod +x ${script}
echo "generate ${script} from errors log ${log}"
${git_command} 2>&1 | grep 'exists' | sed -n "s:.*\: 'refs/tags/\(.*\)' exists;.*:git tag -d '\1':p" >> ${script}
echo "execute ${script}"
${script}
git pull
The script above will log errors to XXX-errors.log and fix them by generating and running a XXX-exist-tags-delete.sh automatically from the XXX-errors.log using the following commands:
- git update-ref -d refs/tags
- git fetch
- git pull
Solution 7 - Git
First Solution ==>:let's say you have branch called develop and you're trying to create new branch called develop/updatefeature this will cause this error, that was my case so If you remove the develop word from the new branch (updatefeature)I think It should be solved the issue.
Second Solution ==>: use the below command in bash
git remote prune origin
Solution 8 - Git
For a quick work around you can use
git push --delete origin 'v2.8'
git push --delete origin 'v2.9'
Solution 9 - Git
This is what I tried and it worked for me.
git remote prune origin
Solution 10 - Git
I was trying to push (/dev/somechanges) and I have a remote branch (/dev) with the same prefix when I choose a new name that is not starting with /dev it worked fine.