Can I point to .git / config to extract multiple refspec?

I do not want to get each branch from the source, because there are many of them. I just want to track multiple (e.g. master ) and my branches (organized in the my_name subdirectory). 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 the above "set" of refspecs to be the default git fetch . I 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 

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 this 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

+23
git
Mar 19 '13 at 18:10
source share
3 answers

You can add the following lines to .git/config to specify multiple refspec to extract:

 [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 refspec if you want to also override the selection of links without fast-forward, for example:

 [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* not supported, but a/b/* is).

10.5 Git Internal - Refspec

+26
Mar 19 '13 at 19:31
source share

Note: if you want to extract one call from another refspec (temporarily overriding the refcpec registered in the config), you can do this with Git 2.1 (August 2014).

See commit c5558f8 Junio โ€‹โ€‹C Hamano ( gitster ) :

Since the advent of opportunistic updates to remote tracking branches, it started around f269048 ( fetch : opportunistically update tracking links, 2013-05-11) with several updates in the v1.8.4 era, the remote.*.fetch Fetch configuration always works even if the command line parameter is specified refspec to indicate what to choose, and there is no way to disable or override it for each call .

Teach the command to pay attention to the command line --refmap=<lhs>:<rhs> , which can be used to override the use of configured remote.*.fetch Fetch as refmap.

This gives you a new opportunity:

 --refmap=<refspec> 

When retrieving the links listed on the command line, use the specified refspec (can be provided more than once) to map refs links to remote tracking branches instead of the remote.*.fetch values โ€‹โ€‹of the configuration variables for the remote repository. <w> For details, see the "Configured Remote Tracking Branches" section.

(This Git section, โ€œConfigured Remote Track Branches,โ€ also dates to Git 2.1: see โ€œ Having a difficult understanding of git fetch โ€)

+4
Aug 02 '14 at 18:12
source share

To overwrite existing fetch refetch options without having to manually edit .git/config , you can use --unset-all and then as much as possible --add .

For an example of the required reflexes in a question, this would be:

  $ git config --unset-all remote.origin.fetch $ git config --add 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 

Then use git config --get-all remote.origin.fetch to check the result.

+3
Apr 07 '17 at 14:32
source share



All Articles