1

I have a remote from which I fetch only one branch:

[remote "upstream"]
    url = ....
    fetch = +refs/heads/foo:refs/remotes/upstream/foo

I want to add another branch to the set of branches I fetch from this same remote.

I know I can edit local .git/config and add a second fetch clause by hand:

[remote "upstream"]
    url = ....
    fetch = +refs/heads/foo:refs/remotes/upstream/foo
    fetch = +refs/heads/bar:refs/remotes/upstream/bar

Ergo, I can invoke the git config magic to do same thing without editing the config file:

 git config --local --add remote.upstream.fetch +refs/heads/bar:+refs/remotes/origin/bar

Both approaches (mentioned, in particular, in answers to another question) look quite low-level to me. Is there a higher level git command to add a branch to the set of remote refs, just like remote add -t <branch> .... that was initially used to create the single branch refs?

Community
  • 1
  • 1

1 Answers1

1

Not that I know of.

The easiest way would be to script that "high level command" yourself, in bash (even on Windows), calling it git-addfetchbr.sh (to be stored anywhere in your $PATH).
That would allows you to type:

git addfetchbr upstream bar bar

The script would do a:

git config --local --add remote.$1.fetch +refs/heads/$2:+refs/remotes/$1/$3
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250