【问题标题】:specify default branch for a non-default remote for pull为拉取的非默认远程指定默认分支
【发布时间】:2011-11-19 09:07:04
【问题描述】:

我将远程源设置为当前分支的默认分支。我还有一个上游遥控器,它不是分支的默认设置。有没有办法在遥控器上配置一个默认分支,所以当我拉它时默认到那个分支?

这是我的 .git/config:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:studgeek/knockout.git
[branch "gh-pages"]
        remote = origin
        merge = refs/heads/gh-pages
[remote "upstream"]
        url = git://github.com/SteveSanderson/knockout.git
        fetch = +refs/heads/*:refs/remotes/upstream/*
        merge = refs/heads/gh-pages

有了这个我可以很高兴地做以下事情,它默认为origin/gh-pages

git pull

我想做的只是给它远程上游并让它找出分支(gh-pages)部分

git pull upstream

而不是这个

git pull upstream gh-pages

如果我省略分支,现在我会得到以下信息:

$ git pull upstream
You asked to pull from the remote 'upstream', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

我可以看到三种不同的默认方式,在我目前的情况下对我有用,但我不知道如何做任何一种:): * 只需使用当前分支作为远程上游的默认分支 * 为当前分支指明上游远程的默认分支(同时将 origin 保留为默认分支) * 表示遥控器上的默认分支。如果我切换分支,这里的危险当然是默认的上游分支保持不变。在我的情况下,这很好,但我可以看到那些没有预料到的燃烧的人。

注意specifying git branch for remote 提出了类似的问题,但解决方案需要做我们不想做的两件事之一 - 更改默认远程或显式列出分支(我们希望对此进行编码以避免手动错误)。

【问题讨论】:

    标签: git github


    【解决方案1】:

    在 .git/config 中,您可以提供信息。例如,如果您在分支 foo 并且您想从 moo 远程拉取

    [branch "foo"]
       remote = origin
       merge = refs/heads/moo
    

    下次您在分支foo 中运行git pull 时,它将从moo 拉取。

    这已经在 stackoverflow 中介绍过 => How do you get git to always pull from a specific branch?

    【讨论】:

    • 这不能回答问题,因为这只适用于默认远程(来源)!
    猜你喜欢
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2022-01-09
    • 1970-01-01
    相关资源
    最近更新 更多