0

I've initially created (by mistake) a local git branch named dev-doc which I later removed successfully.

Despite doing so, VS Code continues to show me the old name of the branch, while pointing the HEAD to the same ID of the new branch dev.

enter image description here

How can I get rid of the incorrect branch from the list?

I've checked the .git/config file without success.

core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.hookspath=.husky
remote.origin.url=https://github.com/andreamoro/site.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.dev.url=https://github.com/dev/andreamoro.git
remote.dev.fetch=+refs/heads/*:refs/remotes/dev/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
pull.rebase=false

Nothing useful in the .vscode folder within the project too. The git remote -v shows exactly one branch.

The git branch -avv however shows all that content shown by the IDE, but yet I don't know from where this is taken.

* main                                               4046d17 [origin/main] fix: minor fixes
  remotes/dev-doc/feature/paginated-page-noindex     374a00c feat: prevent robots pages
  remotes/dev-doc/feature/update-documentation       6a1fb4b docs(readme): add deployment guidelines
  remotes/dev-doc/main                               324a8a2 Merge pull request #21 from dev/feature/paginated-page-noindex
  remotes/dev/feature/paginated-page-noindex         374a00c feat: prevent robots pages
  remotes/dev/feature/update-documentation           6a1fb4b docs(readme): add deployment guidelines
  remotes/dev/main                                   324a8a2 Merge pull request #21 from dev/feature/paginated-page-noindex
  remotes/origin/HEAD                                -> origin/main
  remotes/origin/feature/paginated-page-noindex      374a00c feat: prevent robots pages
  remotes/origin/main                                4046d17 fix: minor fixes

As you can see the remotes/dev/feature/update-documentation and remotes/dev-doc/feature/update-documentation are pointing to the same location. I created the latter by mistake, then I created the first in the attempt to get rid of the first. Now they are both listed, but I need only one. They are not a remote branch as I don't have writing permission on that remote to create branches.

A git remote -v shows the following

dev https://github.com/xyz/repo.git (fetch)
dev https://github.com/xyz/repo.git (push)
origin  https://github.com/me/me-site.git (fetch)
origin  https://github.com/me/me-site.git (push)
Andrea Moro
  • 676
  • 2
  • 9
  • 20
  • 1
    1) What specifically about that `git branch` output is undesirable to you? I don't see _any_ local branches other than `main`. The rest of the branches are remote branches not being tracked by local branches on your machine. and I don't see a `dev-doc` branch. 2) There _is_ a `dev-doc` _remote_. Branches and remotes are completely different things. Please clarify your usage of terminology. 3) Do you mean that VS Code is showing branches that are not shown in that `git branch` output? – starball Feb 09 '23 at 22:41
  • remotes/dev/feature/update-documentation and remotes/dev-doc/feature/update-documentation are pointing to the same location .. infact I created the latter by mistake ... then I created the first in the attempt to get rid of the first. Now they are both listed, but I need only one. They are not a remote branch... the remote is only one `feature/update-documentation` for instance – Andrea Moro Feb 09 '23 at 22:51
  • weird that `dev-doc` doesn't show up in your `.git/config`. Also weird how your `.git/config` file looks like that. mine always have headings like `[core]` and `[remote "origin"]`. What folders exist under your `.git/refs/remotes/` folder? – starball Feb 10 '23 at 18:25
  • Here it is where that reference is ... – Andrea Moro Feb 10 '23 at 18:34
  • I don't understand what you just said. Please elaborate. What is "_it_"? What is "_that reference_"? Where is "_that reference_"? – starball Feb 10 '23 at 18:45
  • That's what the problem was. You pointed out into the resolution, there was this additional folder in the .gif/refs/remotes that was showing up the duplicates. – Andrea Moro Feb 11 '23 at 04:26

2 Answers2

0

Thanks to the support of @user I figured out a reference in .git/refs/remotes remained in place from my previously created branch.

Deleting the folder sorted out the problem.

Andrea Moro
  • 676
  • 2
  • 9
  • 20
0

You had a leftover folder named dev-doc in your .git/refs/remotes folder. It's weird that that was there, since the proper way of removing a remote is to do git remote remove <remote_name>, and through that approach, git will delete the corresponding folder in .git/refs/remotes, and remove all local information about remote branches from the removed remote (I know because I just tried it).

Since your .git/config file looks unconventionally written, I'll wager you were working with it by hand (nothing inherently wrong with that), but didn't use the proper way (git remote remove) to remove the remote you added (you shouldn't do that), and you instead just deleted the line that specifies the remote from your .git/config files.

I wager that because you didn't even know the difference between remotes and branches. I suggest reading the following:

starball
  • 20,030
  • 7
  • 43
  • 238
  • Just for precise it, I never edited manually the config file or any other manually. It was for me an attempt to try to understand where things were, up an until you helped me. So thanks for this. Git is apparently having its own little world of complexities I'm not used to. – Andrea Moro Feb 12 '23 at 08:06