Git: cannot checkout branch - error: pathspec '...' did not match any file(s) known to git
Solution 1:
Try git fetch
so that your local repository gets all the new info from Github. It just takes the information about new branches and no actual code. After that, the git checkout
should work fine.
You basically see the branch, but you don't have a local copy yet!...
You can simply fetch and then checkout to the branch, use the command below to do that:
git fetch
git checkout <Branch name here>
I also created the image below for you to share the differences, look at how fetch works, and also how it's different to pull:
Solution 2:
I was getting this error when I tried to checkout new branch:
error: pathspec 'BRANCH-NAME' did not match any file(s) known to git.
When I tried git checkout origin/<BRANCH-NAME>
, I got the detached HEAD:
(detached from origin/)
Finally, I did the following to resolve the issue:
git remote update
git fetch
git checkout --track origin/<BRANCH-NAME>