两个本地分支跟踪单独的远程Git回购

时间:2016-05-07 00:24:01

标签: git github version-control

我有一个有两个分支的本地仓库

  • 私有

我希望master分支从Github上的 public repo跟踪origin / master。我希望私人分支从Github上的私人仓库跟踪origin_private / master。

假设这是一个好主意/良好设置,我遇到了一些问题,试图让这两个分支跟踪单独的远程回购。

例如,请参阅此命令历史记录;我用自己的评论注释了它:

C:\Users\denman\WebstormProjects\suman>git branch
* master
  private

C:\Users\denman\WebstormProjects\suman>git branch -u origin/master master
Branch master set up to track remote branch master from origin. (cool thanks Git)

C:\Users\denman\WebstormProjects\suman>git checkout private
Switched to branch 'private'

C:\Users\denman\WebstormProjects\suman>git branch -u origin_private/master master
Branch master set up to track remote branch master from origin_private.
(cool thanks Git)

C:\Users\denman\WebstormProjects\suman>git pull
There is no tracking information for the current branch. (not cool Git!)
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> private

有谁知道我做错了什么?我使用“git branch -u”命令发出标准调用以跟踪远程分支,但它似乎不起作用。

1 个答案:

答案 0 :(得分:3)

首先设置master以跟踪origin/master,然后重新设置master以跟踪private_origin/master。在第二个跟踪命令中,最后一个参数应为private。实际上,当您private签出时,您可以省略最后一个参数,如果您只想设置跟踪分支,我们可以省略结帐。