Git: cannot checkout branch - error: pathspec '...' did not match any file(s) known to git
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
[email protected]:~/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 [email protected]:~/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?
I found this post, and running
git show-ref gives me:
97e2cb33914e763ff92bbe38531d3fd02408da46 refs/heads/develop c438c439c66da3f2356d2449505c073549b221c1 refs/heads/feature/datts_right 11a90dae8897ceed318700b9af3019f4b4dceb1e refs/heads/feature/user_controlled_menu c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/heads/master c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/remotes/origin/HEAD e7c17eb40610505eea4e6687e4572191216ad4c6 refs/remotes/origin/develop c438c439c66da3f2356d2449505c073549b221c1 refs/remotes/origin/feature/datts_right c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/remotes/origin/master 23768aa5425cbf29d10ff24274adad42d90d15cc refs/stash e572cf91e95da03f04a5e51820f58a7306ce01de refs/tags/menu_shows_published_only 429ebaa895d9d41d835a34da72676caa75902e3d refs/tags/slow_dev
.git directory (
user_controlled_site_layouts is in the
$ ls .git/refs/heads/feature/ datts_right user_controlled_menu user_controlled_site_layouts $ cat .git/refs/heads/feature/user_controlled_site_layouts 3af84fcf1508c44013844dcd0998a14e61455034
git show 3af84fcf1508c44013844dcd0998a14e61455034
$ git show 3af84fcf1508c44013844dcd0998a14e61455034 commit 3af84fcf1508c44013844dcd0998a14e61455034 Author: Ramon Tayag <[email protected]> Date: Thu May 12 19:00:03 2011 +0800 Removed site layouts migration diff --git a/db/schema.rb b/db/schema.rb index 1218fc8..2040b9f 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110511012647) do +ActiveRecord::Schema.define(:version => 20110503040056) do create_table "attachments", :force => true do |t| t.string "name" @@ -205,15 +205,6 @@ ActiveRecord::Schema.define(:version => 20110511012647) do t.integer "old_id" end - create_table "site_layouts", :force => true do |t| - t.string "name" - t.text "description" - t.text "content" - t.integer "site_id" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "site_styles", :force => true do |t| t.text "published" t.datetime "created_at"
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.
Read more... Read less...
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>
I got this error for a branch that was remote and had no local tracking branch. Even though I'm certain I've checked out remote branches via a simple
git checkout feature/foo
in the past, to get around this error I had to
git checkout -t -b feature/foo origin/feature/foo
I have no idea what I did to get myself into that situation either.
If you deleted a branch with
git branch -D yourbranchname and pulled/cloned again your repo, you may need to create your local branch again.
git checkout -b yourbranchname
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
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
Then, you can try "git pull" (maybe "git fetch origin" also works but I didn't try) to get all the branch.
Git Windows users beware - without the
GIT_ICASE_PATHSPECS = 1 env var setting, that git pathspecs will be case-sensitive, in which case
git checkout origin/FooBranch "Some/Path/To/File.txt"
is not the same as
git checkout origin/FooBranch "some/path/to/file.Txt"