545

I'm using git in VSCodium and each time I try to pull git is complaining.

Looking into the log I see

> git pull --tags origin master
From https://github.com/MY/REPO
 * branch            master     -> FETCH_HEAD
 ! [rejected]        latest     -> latest  (would clobber existing tag)
   9428765..935da94  master     -> origin/master

Doing the command with --force helps until the next time.

It's unclear to me what's going wrong here. What happened and how can I resolve this issue?

I mean: Besides trashing my local repo and cloning again.

6 Answers 6

1260

You should update your local tags with remote tags:

git fetch --tags --force

Then pull again.

Reason

On remote, someone deletes a tag and creates a new one with the same name, then this will happen on your local

9
  • 59
    This worked for me. I was having issues with VSCode then running this in command line fixed the issue. :)
    – Don F.
    Mar 4, 2020 at 0:46
  • 9
    Thanks, can you explain more about this please? Is this a one time command, what exactly was the issue and how does this solved it..
    – Sagiv b.g
    May 30, 2020 at 12:33
  • 33
    @Sagivb.g on remote, someone deletes a tag and create a new one with the same name, then this will happen on your local May 31, 2020 at 17:54
  • 1
    yes - this happened to me since we recently added CI to keep replacing the latest tag
    – Poat
    Sep 9, 2021 at 14:28
  • 5
    If you're working with a fork, be sure to usegit fetch --all --tags --force.
    – gigalul
    Dec 29, 2021 at 13:20
155

Since you say it's unclear what's going wrong, I assume you're not using that tag for anything and you just want to do your own work.

Turn off this setting:

enter image description here

Or add this "git.pullTags": false in the settings.json file`

Now you're all set.


Detailed explanation:

Tags are just references to specific commits (just like branch names). The main difference is that git (as far as I know) assumes tags will not change, where branches are expected to be updated.

So, the "error" is that you have in your local a tag called latest pointing to commit X - but the remote has a tag called latest pointing to commit Y. If you apply the change from the remote you will overwrite your local tag.

VSCode will pull all tags by default, thus you get the error.

There isn't anything wrong with having a "moving" tag like latest, that just isn't something VSCode takes into account (personal opinion).


Alternatively, you can avoid the issue by using the command line and manually entering the git pull command. Specifically, you need to omit --tags to skip this step of the process.

If you do this, your tags will not be updated - but I don't think is a concern here.

8
  • Thanks a lot. I had to update my VSCodium, but then it worked. I think, I could also get rid of my local tag?
    – Skeeve
    Sep 21, 2019 at 20:22
  • 1
    see my answer below Dec 7, 2019 at 4:48
  • 3
    I think this answer is better because it will solve the problem permanently, not just a one-time fix. Especially useful if your team is re-tagging regularly. Jan 13, 2021 at 3:27
  • Even I used the described solution, I also found that the solution described in the article stackoverflow.com/a/5373319/2724543 helps to solve the error.
    – kikea
    Feb 16, 2021 at 12:40
  • for those why cannot see the image, it's Git: Pull Tags [ ] git fetch all tags while pulling in vscode settings
    – Klypto
    May 25, 2021 at 15:35
45

The reason may be that you or other contributors deleted an original tag and recreated the same tag.

The solution:

git fetch --tags -f

Forced to refresh the local tag


When using the button to update the code in the editor, the default will first use git pull --tags origin master

Therefore, you can add this "git.pullTags": false in the configuration file settings.json of the Vscode

0
11

Edit: To be clear, the original question was related to a git issue. While it may not be obvious, yarn can also have git dependencies. So for the 0.1% of users that has this error while running yarn install, this is for you! If not, just use the accepted/top answers.


I got this error for a package while trying to run yarn install. The accepted answer was for the current repo and didn't work for me, but this worked:

rm -rf **/node_modules && yarn cache clean

I'd tried just removing node_modules before, guess cleaning yarn cache was what did it.

5
  • 4
    what is yarn and is it related to git?
    – Skeeve
    Jun 8, 2021 at 6:20
  • 2
    yarn is a package manager, often used as an alternative to npm. Rather than using a package, you can add a git dependency to install from a git repo instead. I assume reseting the yarn cache allows it to update the git tags properly, similar to how the accepted answer suggests to fetch the tags.
    – eckc
    Jun 9, 2021 at 22:43
  • 4
    I wish this wasn't downvoted that much. I get that the original question was strictly for git, but a google search for my yarn error gave me this question as the top result, and this answer was exactly what I needed. Jan 31, 2022 at 19:31
  • 2
    This was exactly what I needed but I didn't see it initially since it was downvoted so much. Thank you @eckc ! Apr 13, 2022 at 16:42
  • 1
    It's a good answer and worked for me, however the dangerous thing is **/. The right thing is to delete only the node modules from the repo you are getting the error. That is: rm -rf ./node_modules && yarn cache clean
    – manuelmhtr
    Jun 21, 2022 at 21:59
2

If this is a regular occurrence where tags are deleted and recreated (for instance, the recommendation for GitHub Actions is to have a floating major version tag), you can edit your .git/config to add the following refspec:

[remote "origin"]                                                                                                                                              
  url = https://github.com/org/repo                                                                                                                 
  fetch = +refs/heads/*:refs/remotes/origin/*                                                                                                                

  # extra refspec
  fetch = +refs/tags/*:refs/tags/*

Since tags are not namespaced per remote, you should understand the impact this could have, but it may make sense for certain use cases.

To explain why this is necessary, see the git-fetch documentation (emphasis mine):

Until Git version 2.20, and unlike when pushing with git-push, any updates to refs/tags/* would be accepted without + in the refspec (or --force). When fetching, we promiscuously considered all tag updates from a remote to be forced fetches. Since Git version 2.20, fetching to update refs/tags/* works the same way as when pushing. I.e. any updates will be rejected without + in the refspec (or --force).

0

Running

git fetch --tags
yarn cache clean

fixed the issue for me when the issue was coming from another symlinked library where I already fixed the issue.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.