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

后端 未结 30 3051
太阳男子
太阳男子 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:36

    Three steps

    1. Write a command 'git fetch'
    2. then you will see the desired branch then switch to the relevant branch 'git checkout 'your_branch_name'
    3. then write a command 'git pull origin your_desired_branch_name'
    0 讨论(0)
  • 2020-11-28 00:38

    I had the same issue for one of my branch.

    These commands work for me.

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

    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>
    
    0 讨论(0)
  • 2020-11-28 00:39

    I copied remote origin url from another .git/config file, doing so my new .git/config file was missing following line in [remote "origin"] section

    fetch = +refs/heads/*:refs/remotes/origin/*
    

    Adding above line fixed error: pathspec 'master' did not match any file(s) known to git.

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

    in my case I enter submodule directory without doing

    • git submodule init
    • git submodule update

    So git was linked to the parent folder that indeed missed that branch.

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

    I encountered this same issue when I was first playing around with git. When attempting my first commit...

    git commit -m 'first commit!'
    

    I got the error mentioned by the OP...

    error: pathspec 'commit!'' did not match any file(s) known to git.
    

    I thought I might have been confusing git by using a keyword in the commit message, so I tried a few other words and received the same error.

    Finally I used double-quotes in the message...

    git commit -m "first commit!"
    

    This turned out to be successful...

    [master (root commit) 0000000] first commit!
    1 file changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 dummyDoc.txt
    
    0 讨论(0)
提交回复
热议问题