Git: cannot checkout branch - error: pathspec '…' did not match any file(s) known to git

后端 未结 30 3050
太阳男子
太阳男子 2020-11-27 23:54

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

相关标签:
30条回答
  • 2020-11-28 00:30

    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.

    0 讨论(0)
  • 2020-11-28 00:31

    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.

    0 讨论(0)
  • 2020-11-28 00:32

    If branch name and you dont have any uncommited file, then try this

    git fetch && git checkout <branch name>
    
    0 讨论(0)
  • 2020-11-28 00:35

    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.

    0 讨论(0)
  • 2020-11-28 00:35

    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

    0 讨论(0)
  • 2020-11-28 00:36

    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>.

    0 讨论(0)
提交回复
热议问题