另一远程上的Checkout分支 [英] Checkout branch on different remote
问题描述
我有一个仓库,除了起源
之外,还有一个远程上游
。我可以执行 git checkout源/主服务器
,但是当我运行 git checkout上游/主服务器
时,我得到:
I have a repo that has another remote upstream
besides origin
. I can do git checkout origin/master
, but when I run git checkout upstream/master
, I get:
error: pathspec 'upstream/master' did not match any file(s) known to git.
这也不起作用:
$ 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?
如何在上游
远程签出分支就像我在原始
远程上所做的一样?我的git版本是2.1.2。
How to check out branches on upstream
remote as I do on origin
remote? My git version is 2.1.2.
推荐答案
只需从远程获取引用(这将获取所有分支,提交,引用
Just fetch the refs from the remote (this will fetch all branch, commit, refs etc for the upstream repo)
git fetch upstream
之后,签出所需的分支(这将创建分支的本地副本)
After this, checkout the needed branch (this creates a local copy of the branch)
git checkout -b <branchname> --track upstream/<branchname>
现在,如果您想将来在此分支中进行更改,您要做的就是
Now if you want to pull the changes in this branch in future, all you need to do is
git pull upstream <branchname>
如上所述在此处,尝试对分支名称进行显式提取:
As mentioned here, try doing an explicit fetch on the branch name:
git fetch upstream master:branch_name
这篇关于另一远程上的Checkout分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!