mhadar
mhadar

Reputation: 49

how to delete duplicate local branch in git which does not exist

I searched for similar questions posted here and on the web, but none of them refer to my case.

In some way, I accidentally created a duplicate local branch as you can see in the attached screenshot. git graph screenshot My guess is that I created it somehow when I was working with git stash with multiple stashes. This duplicate branch appears only locally. And moreover, the command git branch in this repo returns only the master branch.

How can I fix this and remove the duplicate local branch? I do want to keep the tags in their place (and I do see them in GitHub so they indeed exist in origin/master branch although they do not appear here in origin/master). Thank you for your help

Editing due to comments: Before all that mess I accidentally caused, I only saw a single line in the git graph (the blue one) and the tags appeared on it. there was no parallel line next to it showing the same commits. BTW, I cloned the repo to a new location and there I see what I expect - a single line with the tags appear on it. Moreover, I can't push to git from VSCode, but I do succeed in pushing from gitbash, this makes me wonder whether this is some bug in VSCode.

git log --all --graph --format=oneline --decorate prints the expected proper graph, with no duplication: enter image description here

Upvotes: 1

Views: 195

Answers (2)

VonC
VonC

Reputation: 1326994

Note that if the tag was also pushed separately (possibly create/push by another collaborator), a git fetch --tags would bring it back.

While it was not the case for the OP, the command "Git: Delete remote tag" can help, and is introduced with VSCode 1.75 (Jan. 2023) with PR 170415 from the 2020 issue 104845.

This is available in VSCode Insiders today.

Upvotes: 1

mhadar
mhadar

Reputation: 49

For other people facing the same issue.
I'm not sure why it happened but it was caused by the tags created using the git-graph extension in VSCode.
To fix this: manually deleted all tags locally only and then fetch them back using git fetch --all --tags.

Upvotes: 1

Related Questions