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 checkou
I had the same issue.. I thought I had branch named foo
when I try to:
git checkout foo
I was getting:
error: pathspec 'foo' did not match any file(s) known to git.
Then I tried the full branch name:
git checkout feature/foo
then worked for me.
I have the same questions, and got some information from this link: git fetch doesn't fetch all branches
So now, I may not sure how this situation happened, at least we can solve it:
Step 1. Check your "remote.origin.fetch" setting, should be like this
$ git config --get remote.origin.fetch
+refs/heads/private_dev_branch:refs/remotes/origin/private_dev_branch
Step 2. Change "remote.origin.fetch" to fetch everything
$ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
Then, you can try "git pull" (maybe "git fetch origin" also works but I didn't try) to get all the branch.
If branch name and you dont have any uncommited file, then try this
git fetch && git checkout <branch name>
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.
I got this error when trying to checkout a branch via:
git checkout branchX
which I had not checked out before. It only worked when explicitly stating the remote:
git checkout --track origin/branchX
The reason for this was, that I had 2 different remotes (origin + sth. else) configured in git config. As I didn't need the second remote, I removed it and voilá, it worked. The alternative to set the default remote via:
checkout.defaultRemote=origin
did not work for me
In my case I have TWO branch 1) master(which is for live server) 2) dev(test server). I had set multiple remote to push code on respective server. When I tried to switch branch I got the error like error: pathspec 'master' did not match any file(s) known to git.
You can see them by git remote -v
.
I had removed other remote except origin
remote by git remote remove <remote-name>
Then git fetch
Now I am able to checkout branch by git checkout <branch-name>
.