【问题标题】:Add branch to the set of remote fetched branches将分支添加到远程获取的分支集
【发布时间】:2015-04-07 19:16:47
【问题描述】:

我有一个遥控器,我只能从中获取一个分支:

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

我想将另一个分支添加到我从同一个远程获取的分支集合中。

我知道我可以编辑本地 .git/config 并手动添加第二个 fetch 子句:

[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> ....

【问题讨论】:

    标签: git git-remote


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2017-06-24
      • 2021-04-17
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多