0

[Very similar to Why do I see a deleted remote branch?, but none of the solutions there worked.]

When forking a repository you may get a branch which you don't want:

$ git branch -a
* master
  remotes/origin/master
  remotes/origin/merge-brad

Deleting remote branches is a well understood task, so let's do that:

$ git push origin :merge-brad 
To git@github.com:l0b0/fake-s3.git
 - [deleted]         merge-brad

Is it still in the branch list? Yes indeed:

$ git branch -a
* master
  remotes/origin/master
  remotes/origin/merge-brad

Deleting local references to dead branches is also well known. Let's try the first one:

$ git fetch -p
From github.com:l0b0/fake-s3
 * branch            master     -> FETCH_HEAD

Nope:

$ git branch -a
* master
  remotes/origin/master
  remotes/origin/merge-brad

Alright, how about the second one:

$ git remote prune origin

Still nope:

$ git branch -a
* master
  remotes/origin/master
  remotes/origin/merge-brad

And the third:

$ git remote prune origin
$ git branch -a
* master
  remotes/origin/master
  remotes/origin/merge-brad

The branch list in GitHub doesn't display merge-brad anymore, but the local copy refuses to acknowledge this, so now what? Is my Git configuration breaking this somehow?

$ git --version
git version 2.8.3
l0b0
  • 55,365
  • 30
  • 138
  • 223

1 Answers1

0

My bad. I'd applied a configuration change to get upstream pull requests without looking closely at the command:

git config remote.origin.fetch "+refs/pull/*/head:refs/remotes/upstream/pr/*"

I had assumed that the result would be that pulls of upstream would retrieve pull requests, but of course this modifies origin.

The fix:

$ git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
l0b0
  • 55,365
  • 30
  • 138
  • 223
  • You can have multiple `fetch` settings for each remote. Prune gets squirrelly in some complex cases, though, when it doesn't realize there are multiple ways to acquire some remote-tracking branch (fixed in more recent Git versions). – torek Jun 18 '16 at 21:38