git remote命令中的'set-branches'是什么意思?

5
1个回答

5

这个功能在2010年5月的Git v1.7.2-rc0中引入,提交记录3d8b694中加入了如下注释:

Add git remote set-branches

Add ‘git remote set-branches’ for changing the list of tracked refs for a remote repository with one "porcelain-level" command.
This complements the longstanding ‘git remote add --track’ option.

The interface is based on the ‘git remote set-url’ subcommand.

git remote set-branches base --add C
git remote set-branches base A B D
git remote set-branches base --delete D; # not implemented

所以,与其使用默认的全局refspec来跟踪在refs/remotes/<name>/命名空间下的所有分支,我们需要更新refspec,只跟踪<branch>分支。

git remote add -t main o2 https://github.com/git/git

会给:

[remote "o2"]
        url = https://github.com/git/git
        fetch = +refs/heads/main:refs/remotes/o2/main

改写成:

    fetch = +refs/heads/*:refs/remotes/origin/*

添加一个分支的步骤如下:

   git remote set-branches o2 --add master
[remote "o2"]
        url = https://github.com/git/git
        fetch = +refs/heads/main:refs/remotes/o2/main
        fetch = +refs/heads/main:refs/remotes/o2/master

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接