【问题标题】:Get new upstream branch with git使用 git 获取新的上游分支
【发布时间】:2013-03-21 18:23:38
【问题描述】:

我已经分叉了一个 repo,我的所有工作都进入了那个 fork(我的起源),我将上游分支与拉取请求合并。相当标准。

但是现在上游仓库中有一个新分支,我不知道如何在本地获取该新分支,然后将其推送到我的原点。这是我的情况。

$ git remote show origin
* remote origin
  Fetch URL: git@github.com:rackspace/jclouds.git
  Push  URL: git@github.com:rackspace/jclouds.git
  HEAD branch: master
  Remote branches:
    1.5.x                   tracked
    master                  tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

$ git remote show upstream
* remote upstream
  Fetch URL: https://github.com/jclouds/jclouds
  Push  URL: https://github.com/jclouds/jclouds
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

我知道 jclouds/jclouds 中有一个 1.6.x 分支,我想在本地获取该分支,然后将其推送到 rackspace/jclouds。我试过这个命令

$ git fetch upstream 1.6.x
From https://github.com/jclouds/jclouds
 * branch            1.6.x      -> FETCH_HEAD

看起来它已获取分支,但我在 git remote showgit branch -a 中看不到它,因此我无法设置本地跟踪分支。

我错过了什么?

【问题讨论】:

    标签: git git-branch


    【解决方案1】:

    应该够了

    # I prefer fetching everything from upstream
    git fetch upstream
    
    # Then I track the new remote branch with a local branch
    git checkout -b 1.6.x --track upstream/1.6.x
    git push origin 1.6.x
    

    如果有更新问题,例如:

    fatal: Cannot update paths and switch to branch '1.6.x' at the same time. 
    Did you intend to checkout 'upstream/1.6.x' which can not be resolved as commit?"
    

    如果这也不起作用:

    git checkout upstream/1.6.x -b 1.6.x
    

    那么更简单的版本是:

    # let's create a new local branch first
    git checkout -b 1.6.x
    # then reset its starting point
    git reset --hard upstream/1.6.x
    

    OP Everett Toews 在他的情况下必须做的是:

    最终我不得不用

    显式添加上游分支
    git remote add --track 1.6.x upstream-1.6.x https://github.com/jclouds/jclouds 
    

    然后:

    git pull upstream-1.6.x 1.6.x
    

    【讨论】:

    • 我做了 git fetch 但是当我尝试 git checkout 我得到错误“致命:无法更新路径并同时切换到分支'1.6.x'。你打算结帐吗' upstream/1.6.x' 哪个不能被解析为提交?”
    • @EverettToews git checkout upstream/1.6.x -b 1.6.x 会更好吗?
    • @EverettToews 如果这不起作用,我在答案中添加了一个“重置”选项供您尝试。
    • git checkout upstream/1.6.x -b 1.6.x 给了我与上述相同的致命错误。对于git checkout 1.6.x,我自然会得到“错误:pathspec '1.6.x' 与 git 已知的任何文件都不匹配。”
    • @EverettToews 抱歉,我忘记了-bgit checkout -b 1.6.x,然后是git reset
    猜你喜欢
    • 1970-01-01
    • 2019-05-30
    • 2021-01-27
    • 1970-01-01
    • 2023-01-14
    • 2018-03-12
    • 2015-04-24
    • 2021-08-09
    • 1970-01-01
    相关资源
    最近更新 更多