Git: Cannot Checkout Branch - Error: Pathspec '…' Did Not Match Any File(S) Known To Git

745    Asked by amit_2689 in Devops , Asked on Nov 18, 2022

I'm not sure why I'm unable to checkout a branch that I had worked on earlier. See the commands below (note: co is an alias for checkout):


chandra@chandra-desktop:~/source/unstilted$ git branch -a
* develop
  feature/datts_right
  feature/user_controlled_menu
  feature/user_controlled_site_layouts
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/feature/datts_right
  remotes/origin/master
chandra@chandra-desktop:~/source/unstilted$ git co feature/user_controlled_site_layouts 
error: pathspec 'feature/user_controlled_site_layouts' did not match any file(s) known to git.
I'm not sure what it means, and I can't seem to find anything I can understand on Google.

How do I checkout that branch, and what may I have done to break this?

Answered by Al German

I was getting this error - did not match any file(s) known to got 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/, 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/

Your Answer

Interviews

Parent Categories