I have an account on github
and I use it from two different machines. On one, I created a new branch myNewBranch
and switched to it. Then I did my modifications to my code, I committed and pushed to 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?
我错过了什么?
3 个解决方案
#1
25
You need to fetch the data onto your local repository on machine 2 first:
您需要先在机器2上的本地存储库中获取数据:
$ git fetch origin
$ git checkout origin/myNewBranch
#2
10
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。
#3
1
Try doing git checkout origin/myNewBranch
.
尝试做git checkout origin / myNewBranch。
#1
25
You need to fetch the data onto your local repository on machine 2 first:
您需要先在机器2上的本地存储库中获取数据:
$ git fetch origin
$ git checkout origin/myNewBranch
#2
10
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。
#3
1
Try doing git checkout origin/myNewBranch
.
尝试做git checkout origin / myNewBranch。