2015-04-07 33 views
1

我有我從中獲取只有一個分支遠程:添加分支到組遠程獲取分支

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

我想另一個分支添加到組支路我從同一遠程讀取。

我知道我可以編輯本地.git/config和手工添加第二個取子句:

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

人機工程學,我可以調用git config魔術做同樣的事情,而無需編輯配置文件:

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

這兩種方法(特別是在answers to another question中都提到)對我來說看起來相當低級。是否有更高級別的git命令將分支添加到遠程參考集中,就像remote add -t <branch> ....最初用於創建單個分支參考?

回答

1

不是我所知道的。

最簡單的方法是在bash中(甚至在Windows上)自己編寫「高級命令」,將其命名爲git-addfetchbr.sh(將存儲在您的$PATH中的任意位置)。
這將允許您鍵入:

git addfetchbr upstream bar bar 

該腳本會做:

git config --local --add remote.$1.fetch +refs/heads/$2:+refs/remotes/$1/$3 
+0

偉大的想法,謝謝! – kkm