2

This might be against the design philosophy of git, but:

in my org, I am constantly pulling down thousands of developer branches, named e.g. Dev/<login>/<something...>

I'd much rather have git, by default, not pull down these branches. And then, if it turns out I do need to collaborate in a specific branch, I would just explicitly pull it down.

Is this possible? (My scant research indicates no)

Thanks

Aaron Fi
  • 10,116
  • 13
  • 66
  • 91
  • 1
    `.gitignore` would be the wrong place to put that. You'll need to adjust the `fetch` specifications in your `.git/config` for the appropriate remotes. Try to play around with some wildcards in there. Sorry, I'm not knowledgeable enough to help you out any further, but would love to see a working solution. :-) – Torbjörn Aug 07 '16 at 19:55
  • Possible duplicate of [Can git permanently ignore a remote branch?](http://stackoverflow.com/questions/16842426/can-git-permanently-ignore-a-remote-branch) – Dominik George Aug 07 '16 at 20:24

2 Answers2

3

git-pull uses git-fetch.

See https://git-scm.com/docs/git-fetch for its documentation, especially the "Configure remote-tracking branches" section (attached verbatim below).

Looking at that, you can only whitelist patterns, not exclude some. What you could do therefore is one of:

  • Manually list the branches you want to pull from instead of the wildcard
  • Get everyone to use a prefix for all branches, so that you can distinguish between Dev/* and Foo/*

git fetch allows you to configure remote.<repository>.fetch configuration variables.

Typically such a variable may look like this:

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

This configuration is used in two ways:

When git fetch is run without specifying what branches and/or tags to fetch on the command line, e.g. git fetch origin or git fetch, remote.<repository>.fetch values are used as the refspecs—​they specify which refs to fetch and which local refs to update. The example above will fetch all branches that exist in the origin (i.e. any ref that matches the left-hand side of the value, refs/heads/) and update the corresponding remote-tracking branches in the refs/remotes/origin/ hierarchy.

torek
  • 448,244
  • 59
  • 642
  • 775
Dominik George
  • 516
  • 2
  • 15
3

You can always simply fetch the current branch that you are working on and only this branch.

I'd much rather have git, by default, not pull down these branches

# pull only the current branch you are working on
# git pull = git fetch && git merge
git pull origin <branch name>

Now when you need to merge your branch you can always use this syntax to pull/merge it:

# grab the remote branch
git pull origin Dev/<branch name>

Another way is to "play" with your refspec but im not recommending doing so even due that its pretty simple.

Here is a sample form the documentation:

... However, you can use namespaces (or directories) to accomplish something like that.

If you have a QA team that pushes a series of branches,
and you want to get the master branch and any of the QA team’s branches but nothing else, you can use a config section like this:

[remote "origin"]
    url = https://github.com/schacon/simplegit-progit
    fetch = +refs/heads/master:refs/remotes/origin/master
    fetch = +refs/heads/qa/*:refs/remotes/origin/qa/*
CodeWizard
  • 128,036
  • 21
  • 144
  • 167