3

I have GitHub for Windows installed. When I run "git branch -a", it shows many remote tracking branches, and they appear to be pull requests.

One co-worker who uses Git for Windows doesn't see this, but another co-worker who also uses GitHub for Windows sees the same result.

Example: I forked "bootstrap-sass". On github.com, I used the "Clone in desktop" button. It opens GitHub for Windows, and adds the new repo to my list of local repos.

Running "git branch -a", it returns over 100 results, most of them are "/pr/#". Below is a small sample:

C:\gh-ui\bootstrap-sass [master]> git branch -a
  bower
* master
  remotes/kenshub/2.0-stable
  remotes/kenshub/2.1-stable
  remotes/kenshub/HEAD -> kenshub/master
  remotes/kenshub/gh-pages
  remotes/kenshub/master
  remotes/kenshub/next
  remotes/origin/bower
  remotes/origin/master
  remotes/origin/pr/3
  remotes/origin/pr/4
  remotes/twbs/2.0-stable
  remotes/twbs/2.1-stable
  remotes/twbs/gh-pages
  remotes/twbs/master
  remotes/twbs/next
  remotes/twbs/pr/1
  remotes/twbs/pr/10
  remotes/twbs/pr/103

I'm guessing it's GitHub for Windows. How can I hide the "pr" remote branches? Is it a git config, or part of the "Clone in desktop" command?

yazzer
  • 523
  • 5
  • 10
  • If I use "git clone" through command line, I don't get the extra "/pr/" remote tracking branches. If I use "Clone in Desktop", GitHub for Windows is doing something extra, and I end up with a bunch of "/pr/" remote tracking branches. What more is GitHub for Windows doing, and what else is different than a plain "git clone"? See this 2.5 minute video screencast: http://screencast.com/t/oSS43ednMHyZ – yazzer Sep 16 '14 at 16:58
  • I've never had this problem until a recent update to GitHub for Windows. Very annoying. – KingCronus Mar 25 '15 at 12:20

3 Answers3

1

When cloning a repo, don't use the "Clone in Desktop" option if you have GitHub for Windows installed. Instead, copy the clone URL and run git clone <url> through command line.

When you clone through GitHub for Windows, it is running extra commands like:

fetch origin +refs/pull/*/head:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/* --prune
status --untracked-files=all --porcelain -z

If you don't want to re-clone the repo, then refer to the other answer about deleting branches, and make sure you don't have a fetch refs congif to get "/pr/" branches. View your .git/config file, or run git config --list --local.

yazzer
  • 523
  • 5
  • 10
  • To see what commands are being run by GitHub for Windows, view the debug log. Click on the gear, `About -> Open Debug Log` – yazzer Sep 16 '14 at 17:24
0

You cannot hide, you you could delete those remote tracking branches.
Following "Can you delete multiple branches in one command with Git?", you can try something similar to:

git branch -D `git for-each-ref --format="%(refname:short)" refs/remotes/*/pr/*`

(or you can use other expressions with awk and xargs)

This is similar to deleting one remote tracking branch.

But understand that it is a temporary solution: the next fetch, if configured by default fetch = +refs/heads/*:refs/remotes/origin/*, would bring back all remotes branches.
As explained in "Git Internals - The Refspec", you can also configure multiple fetch in order to bring only the remote tracking branches that you want to see.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the answer. I couldn't get the different options for deleting multiple branches to work. I did learn about the fetch refs config. I'll add a comment to my question with a video showing the issue in more detail. – yazzer Sep 16 '14 at 16:52
0

It is also possible to manually edit the .git/config file and don't track all upstream branches but specific ones.

[remote "upstream"]
  url = https://github.com/xyz/xyz.git
  fetch = +refs/heads/*:refs/remotes/upstream/*

Replace the '*' with specific branch name

[remote "upstream"]
  url = https://github.com/rsocket/rsocket-java.git
  fetch = +refs/heads/1.0.x:refs/remotes/upstream/1.0.x

Then you need to delete remote tracking branches one by one

git branch -d -r upstream/0.2.x

Deleting the references - this don't delete remote branches, it just removes from local.

Batch pruning - this deletes the remote branchs

phoad
  • 1,801
  • 2
  • 20
  • 31