Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fetch/pull multiple branches matching a wildcard string?

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!

like image 996
Jason L Avatar asked Jan 23 '15 17:01

Jason L


1 Answers

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
like image 91
Etan Reisner Avatar answered Sep 28 '22 16:09

Etan Reisner