0

When I use the git branch command, it displays only one local branch: master

However, when I use the git branch -a command, it displays the initial master branch as well as two remote master branches:
remotes/wilhelm/master
remotes/origin/master

Why do I have two remote branches and how do I delete the extra branch without deleting my remote repo?

Wilhelm
  • 1,407
  • 5
  • 16
  • 32
  • 2
    It's not an "extra" branch; evidently you have a `master` branch in each of your remote repos. If you *really* want to delete a remote branch, then refer to the answers e.g. [here](http://stackoverflow.com/questions/2003505/how-to-delete-a-git-branch-both-locally-and-remotely). – Oliver Charlesworth Jun 30 '14 at 21:38
  • @OliCharlesworth I'm confused; I only have one remote repository but two references to the same repo. Is this an error on my part? – Wilhelm Jun 30 '14 at 22:07
  • @Wilhelm how do you know that they're both the same repo? What's the output of `git remote -v`? Oh wait, you already removed it right? Well, so much for that...well, what's the output anyways? Edit it into your question. –  Jun 30 '14 at 23:26

2 Answers2

1

It looks like you have two remote repositories. Of course everyone of them has a master branch, so you have two remote master branches.

You can remove remotes with

git remote remove <name>

This will not delete the repository, only your local repo will not track the remote repo any more.

toydarian
  • 4,246
  • 5
  • 23
  • 35
  • I tried removing `remotes/wilhelm/master` with `git remote remove remotes/wilhelm/master` but received the error `error: Could not remove config section 'remote.remotes/wilhelm/master'` – Wilhelm Jun 30 '14 at 22:04
  • Sorry, I didn't make myself clear. You have to use `git remote remove wilhelm` – toydarian Jun 30 '14 at 22:05
  • This removes `[remote "Wilhelm"]` from my `.git/config` file but the remote branch still appears when I call `git branch -a` – Wilhelm Jun 30 '14 at 22:14
  • Then you probably have an tracking branch, this one can be removed with `git branch -d `. But it seems your repo is a little bit broken. Perhaps, you should completely remove it and clone it once again. This is normally faster than fixing a broken repo… – toydarian Jun 30 '14 at 22:20
  • 1
    @toydarian you can't remove tracking branches with `git branch -d`, you need to pass the `--remotes` or `-r` flag with it, i.e. `git branch -dr`. Using `git remote remove` should've removed all remote-tracking branches for the remote though. It even says so in [the documentation](https://www.kernel.org/pub/software/scm/git/docs/git-remote.html). –  Jun 30 '14 at 23:24
0

I ended up manually removing the branch from my .git/refs/remotes/ folder.

I wouldn't recommend any one do this unless:

  • absolutely necessary
  • or you have difficulty letting go [as I do]
Wilhelm
  • 1,407
  • 5
  • 16
  • 32