簡體   English   中英

使用git獲取新的上游分支

[英]Get new upstream branch with git

我已經分叉了一個倉庫,我的所有工作都進入了那個分支(我的起源),並且我將上游的分支與pull請求合並。 很標准。

但是現在上游回購中有一個新分支,我無法弄清楚如何在本地獲取新分支,然后將其推送到我的原點。 這是我的情況。

$ 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 branch -a所以我無法設置本地跟蹤分支。

我錯過了什么?

這應該足夠了

# 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM