Git: can't switch to new remote branch
Solution 1
You need to fetch the data onto your local repository on machine 2 first:
$ git fetch origin
$ git checkout origin/myNewBranch
Solution 2
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
.
Solution 3
Try doing git checkout origin/myNewBranch
.
Ricky Robinson
Updated on October 12, 2020Comments
-
Ricky Robinson over 3 years
I have an account on
github
and I use it from two different machines. On one, I created a new branchmyNewBranch
and switched to it. Then I did my modifications to my code, I committed and pushed tomyNewBranch
.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?
-
Ricky Robinson almost 11 yearsThat worked, thanks! But I did a big mess: in the actions described in my question, I pulled from from myNewBranch to a different branch. Now I would actually like to keep this different branch unaltered remotely and push to myNewBranch the changes I made. Is this possible?
-
Ricky Robinson almost 11 yearsFound it: stackoverflow.com/questions/8550586/…