Git:无法切换到新的远程分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16846115/
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-10 16:17:45  来源:igfitidea点击:

Git: can't switch to new remote branch

gitgithubbranchgit-branch

提问by Ricky Robinson

I have an account on githuband I use it from two different machines. On one, I created a new branchmyNewBranchand switched to it. Then I did my modifications to my code, I committed and pushedto myNewBranch.

我有一个帐户github,我在两台不同的机器上使用它。一方面,我创建了一个新分支myNewBranch并切换到它。然后我对我的代码进行了修改,我提交并送到myNewBranch.

On the second machine, I can't figure out how to push to it.

在第二台机器上,我不知道如何推动它。

$ git pull origin myNewBranch
From https://github.com/myUsername/myProject
 * branch            myNewBranch -> FETCH_HEAD
Already up-to-date.

[ I had already successfully pulled from it]

【我已经成功拉出来了】

Then I try to switch to it, but I get an error:

然后我尝试切换到它,但出现错误:

$ git checkout myNewBranch
error: pathspec 'myNewBranch' did not match any file(s) known to git.

What am I missing?

我错过了什么?

回答by m3rlin45

You need to fetch the data onto your local repository on machine 2 first:

您需要先将数据提取到机器 2 上的本地存储库中:

$ git fetch origin
$ git checkout origin/myNewBranch

回答by cforbish

My guess on what happened there is a remote origin/myNewBranch, but not a local branch myNewBranch. What your command did was to fetch origin/myNewBranch to your current local branch. When you did the git checkout myNewBranch, the error happened because there was no local branch named myNewBranch. I suggest try git checkout -b myNewBranch origin/myNewBranch.

我对发生的事情的猜测是远程源/myNewBranch,而不是本地分支 myNewBranch。您的命令所做的是将 origin/myNewBranch 获取到您当前的本地分支。当您执行 时git checkout myNewBranch,发生错误是因为没有名为 myNewBranch 的本地分支。我建议尝试git checkout -b myNewBranch origin/myNewBranch

回答by Femaref

Try doing git checkout origin/myNewBranch.

尝试做 git checkout origin/myNewBranch