Can I specify in .git/config to fetch multiple refspecs?
git
Solution
You can add the following lines in your `.git/config` to specify multiple refspecs for fetch:
[remote "origin"]
fetch = refs/heads/my_name/*:refs/remotes/origin/my_name/*
fetch = refs/heads/master:refs/remotes/origin/master
fetch = refs/heads/some_branch:refs/remotes/origin/some_branch
You can add the prefix `+` before the refspec, if you would like to override fetching non-fast-forward references as well, like this:
[remote "origin"]
fetch = +refs/heads/my_name/*:refs/remotes/origin/my_name/*
fetch = +refs/heads/master:refs/remotes/origin/master
fetch = +refs/heads/some_branch:refs/remotes/origin/some_branch
Note that partial globbing is not supported (i.e. `a/b/ca*` is not supported, but `a/b/*` is).
10.5 Git Internals - The Refspec
Problem
I do not want to fetch every branch from origin because there are many. I just want to track a few (e.g., `master`) and my branches (organized under `my_name` sub-directory). I can do the following: ``` $ git fetch origin refs/heads/my_name/*:refs/remotes/origin/my_name/* refs/heads/master:refs/remotes/origin/master refs/heads/some_branch:refs/remotes/origin/some_branch ``` I want to specify the above "set" of refspecs to be the default of `git fetch`. I have tried ``` $ git config remote.origin.fetch refs/heads/my_name/*:refs/remotes/origin/my_name/* $ git config --add remote.origin.fetch refs/heads/master:refs/remotes/origin/master ``` It fails: ``` $ git config remote.origin.fetch refs/heads/my_name/*:refs/remotes/origin/my_name/* error: More than one value for the key remote.origin.fetch: refs/heads/master:refs/remotes/origin/master ``` I also try the following but it also fails: ``` $ git config remote.origin.fetch 'refs/heads/my_name/*:refs/remotes/origin/my_name/* refs/heads/master:refs/remotes/origin/master refs/heads/some_branch:refs/remotes/origin/some_branch' $ git fetch fatal: Invalid refspec 'refs/heads/my_name/*:refs/remotes/origin/my_name/* refs/heads/master:refs/remotes/origin/master refs/heads/some_branch:refs/remotes/origin/some_branch' ``` Note: Git 1.7.11