3

I've got a git repo hosted on github. When I do git branch locally I get just the three branches you see in the output below:

$ git fetch
$ git branch
* develop
  kramer65/feature-branch
  master

I then logged into github and on there I see it just has 5 branches:

enter image description here

So now I did a git branch -a locally, which shows my 3 local branches, plus about 40 remote branches:

enter image description here

So then I tried to remove one of the remote branches, but I can't:

$ git push origin :kramer65-feature-branch
error: unable to delete 'kramer65-feature-branch': remote ref does not exist
error: failed to push some refs to 'git@github.com:MyOrganisation/therepo.git'

Any idea why I still see these repos with a git branch -a?

kramer65
  • 50,427
  • 120
  • 308
  • 488

2 Answers2

10

One possible scenario is someone create a branch for development, you run a:

git fetch

will fetch all of those branches. When that feature branch had been merged, they were deleted, and git fetch didn't remove it. You need

git fetch -p

or

git fetch --prune
Danh
  • 5,916
  • 7
  • 30
  • 45
2

You need to remove any remote-tracking references that no longer exist on the remote.

Try this:

$ git fetch --prune
$ git branch -a

# more info
$ git fetch --help
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73