Ricky Robinson Ricky Robinson - 1 month ago 9
Git Question

Git: can't switch to new remote branch

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
.

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?

Answer

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

$ git fetch origin
$ git checkout origin/myNewBranch
Comments