I sometimes use the checkout -b
option to create a new branch, check it out at the same time and set up tracking in one command.
In a new environment, I get this error:
$ git checkout -b test --track origin/master
fatal: Cannot update paths and switch to branch 'test' at the same time.
Did you intend to checkout 'origin/master' which can not be resolved as commit?
Why does Git not like it? This used to work with the same repo.
This simple thing worked for me!
If it says it can't do 2 things at same time, separate them.
You could follow these steps when you stumble upon this issue:
which outputs this:
As you can see the new branch has been fetched from remote.
3. Finally, checkout the branch with this command
It is not necessary to explicitly tell Git to track(using --track) the branch with remote.
The above command will set the local branch to track the remote branch from origin.
It causes by that your local branch doesn't track remote branch. As ssasi said,you need use these commands:
I solved my problem just now....
FWIW: If you have a typo in your branchname you'll get this same error.
You can get this error in the context of, e.g. a Travis build that, by default, checks code out with
git clone --depth=50 --branch=master
. To the best of my knowledge, you can control--depth
via.travis.yml
but not the--branch
. Since that results in only a single branch being tracked by the remote, you need to independently update the remote to track the desired remote's refs.Before:
The fix:
After:
First you need to
Fetch
the remote (the specific branch), then you can create a local br and track it with that remote branch using your command (i.e.checkout
with -b and --track).