14

Currently, when I pull, I get changes from all the branches:

$ git pull
remote: ...
Unpacking objects: ...
From ssh://github.com/...
   a69d94d..a2019da  master     -> origin/master
   b684d4a..b8819dc  develop    -> origin/develop
 + 263c644..f1c1894  gh-pages   -> origin/gh-pages  (forced update)
Updating a69d94d..a2019da

I like this behavior, but I don't need to get content from the gh-pages branch as that only contains generated content. How do I configure Git to fetch from all branches except some (gh-pages). I'd also like to avoid ever seeing gh-pages in my list of local branches.

Jace Browning
  • 11,699
  • 10
  • 66
  • 90
  • Does the answer in http://stackoverflow.com/questions/6368987/how-do-i-fetch-only-one-branch-of-a-remote-git-repository help? Though, it is only about fetch. – tigeronk2 May 17 '14 at 18:11
  • Wouldn't configuring the `remote.origin.fetch` as I mention in my answer include only the branch you want, and not `gh-branch`? – VonC Jun 11 '14 at 19:54
  • @VonC yes, but wouldn't have I have to do this manually do this for every remote branch? – Jace Browning Jun 11 '14 at 20:42
  • The idea is to do it for the only remote branch you want to work on. It will ignore all the others. – VonC Jun 11 '14 at 20:43
  • @VonC what I like about my current behavior of `git pull` is that it automatically adds new remote branches. – Jace Browning Jun 11 '14 at 20:54
  • So you want all remote branches, *except* one or two? – VonC Jun 11 '14 at 20:56
  • @VonC Yes, I'd like to have every remote branch except `gh-pages`. Maybe a script is in order... – Jace Browning Jun 11 '14 at 20:59
  • Indeed. I wouldn't know how to do this kind of fetch exclusion with one git command. – VonC Jun 11 '14 at 21:03

1 Answers1

7

You could modify your config to fetch only one branch:

[remote "origin"]
  fetch = +refs/heads/master:refs/remotes/origin/master

With

git config remote.origin.fetch +refs/heads/master:refs/remotes/origin/master

If you have more than one branch, you can add several fetch directives to fetch those (except gh-pages, the one you don't want to fetch)

See this question for an example of a multiple-branch fetch.

I understand this isn't a solution that scales well, but a fetch refspec doesn't support the normal exclusion syntax (like ^<rev>: see "Specifying ranges").

There is a way to hide a certain refspec, introduced in git 1.8.2: commit daebaa7, "upload/receive-pack: allow hiding ref hierarchies", but that is on the remote side, not one the client side.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250