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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30862558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:07:36  来源:igfitidea点击:

Checkout branch on different remote

gitbranch

提问by Fish Monitor

I have a repo that has another remote upstreambesides origin. I can do git checkout origin/master, but when I run git checkout upstream/master, I get:

我有一个upstream除了origin. 我可以git checkout origin/master,但是当我运行时git checkout upstream/master,我得到:

error: pathspec 'upstream/master' did not match any file(s) known to git.

This does not work either:

这也不起作用:

$ 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?

How to check out branches on upstreamremote as I do on originremote? My git version is 2.1.2.

如何upstream像在远程一样检查远程分支origin?我的 git 版本是 2.1.2。

回答by u1860929

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

回答by nneonneo

If you just added the remote, you'll need to fetchit so that Git knows which branches are available:

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

git fetch upstream master

After this you can do

在此之后你可以做

git checkout upstream/master

without any issues.

没有任何问题。