7

Goal: I have several repositories that are managed by the same rules. I would like to create a git alias to help fetch and/or pull only the relevant branches without fetching information for lots of remote branches relating to work I do not care about. I hope the end result will keep my log output clean and manageable while still giving my relevant information.

Specifics: I would like a single command to pull "master" and any branch starting with "development/" (i.e. development/2.0...). There are several other branches that I would like to avoid fetching. These typically take a form beginning with "integration/" or "personal/".

What I got: I now know what git Porcelain is thanks to a comment in "git fetch --help" and here is how I use it:

git fetch origin master:master -u

This even works to get master and 1 development branch:

git fetch origin master:master development/2.0:development/2.0 -u

But I am having troubles scaling it to every development branch without listing them individually (this appears to do nothing):

git fetch origin development/*:development/* -u

Thanks in advance for the help!

Jason L
  • 73
  • 1
  • 6
  • The `development/*` stuff *should* work, provided your command interpreter does not eat or otherwise mangle the asterisks. Note that the usual local branch names are the "remote tracking" branches, `refs/remotes//...`, not your local branches, so that looks a bit odd. – torek Jan 23 '15 at 20:55
  • See also http://stackoverflow.com/a/20452710/6309 – VonC Aug 16 '15 at 21:31

1 Answers1

4

I don't know that you can do this on the command line but you could do it by configuring the refspec in your git configuration.

Config normally looks something like this.

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

You would want something like this I think (untested)

[remote "origin"]
    fetch = +refs/heads/development/*:refs/remotes/origin/*
    fetch = +refs/heads/master:refs/remotes/origin/*
    url = .....

Though the fetch lines from that might possibly need to be more like these but I'm not sure

    fetch = +refs/heads/development/*:refs/remotes/origin/development/*
    fetch = +refs/heads/master:refs/remotes/origin/master
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • 1
    Took me a couple tries before I realized this needed to be in the individual repository config and not my global git config. fetch = +refs/heads/development/*:refs/remotes/origin/development/* fetch = +refs/heads/master:refs/remotes/origin/master Does exactly what I want. Thank you for the quick response! – Jason L Jan 23 '15 at 21:49
  • How about deleting the block that you said untested? So the next reader just got the straightforward answer. – fikr4n Apr 05 '19 at 09:30