yazzer
yazzer

Reputation: 523

How can I hide the "pr" remote branches?

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?

Upvotes: 3

Views: 1514

Answers (3)

phoad
phoad

Reputation: 1871

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

Upvotes: 0

yazzer
yazzer

Reputation: 523

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.

Upvotes: 1

VonC
VonC

Reputation: 1326366

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.

Upvotes: 0

Related Questions