结帐分支在不同的遥控器上

Fis*_*tor 21 git branch

我有了另一个远程回购upstream之外origin.我能做到git checkout origin/master,但是当我跑步时git checkout upstream/master,我得到:

error: pathspec 'upstream/master' did not match any file(s) known to git.
Run Code Online (Sandbox Code Playgroud)

这也不起作用:

$ git fetch upstream
From https://github.com/getsentry/sentry
 * branch            HEAD       -> FETCH_HEAD
$ git co -b asdf --track upstream/master
fatal: Cannot update paths and switch to branch 'asdf' at the same time.
Did you intend to checkout 'upstream/master' which can not be resolved as commit?
Run Code Online (Sandbox Code Playgroud)

如何在upstream远程检查远程分支origin?我的git版本是2.1.2.

mu *_*u 無 34

只需从远程获取refs(这将获取上游repo的所有分支,提交,引用等)

git fetch upstream
Run Code Online (Sandbox Code Playgroud)

在此之后,签出所需的分支(这将创建分支的本地副本)

git checkout -b <branchname> --track upstream/<branchname>
Run Code Online (Sandbox Code Playgroud)

现在,如果您希望将来在此分支中进行更改,您需要做的就是

git pull upstream <branchname>
Run Code Online (Sandbox Code Playgroud)

如前所述这里,尝试做的分支名明确的获取:

git fetch upstream master:branch_name
Run Code Online (Sandbox Code Playgroud)


nne*_*neo 5

如果您只是添加了遥控器,则需要添加fetch它,以便Git知道哪些分支可用:

git fetch upstream master
Run Code Online (Sandbox Code Playgroud)

之后,您可以做

git checkout upstream/master
Run Code Online (Sandbox Code Playgroud)

没有任何问题。

  • 是的,您可以结帐`upstream/master`,但您将处于“分离头”状态。如果你想让它表现得像你期望的一个分支,你必须像@mu 写的那样使它成为一个跟踪分支。 (3认同)
  • 抱歉,我的意思是`fetch` 不是`pull`。谢谢。 (2认同)