30

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

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

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

[我已经成功拉出来了]

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

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

我错过了什么?

4

3 回答 3

54

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

$ git fetch origin
$ git checkout origin/myNewBranch
于 2013-05-30T21:31:38.647 回答
12

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

于 2013-05-31T03:07:22.883 回答
2

尝试做 git checkout origin/myNewBranch

于 2013-05-30T21:26:44.493 回答