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

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

    I had a different root cause

    I had a script that basically searches all branches matching jira issue key in the for "PRJ-1234" among all branches to execute a git branch checkout command on the matching branch

    The problem in my case was 2 or more branches shared the same jira key and hence caused my script to fail with the aforementioned error

    By deleting the old unused branch and making sure only a single branch had the jira key reference fixed the problem

    Here's my code in case someone wants to use it

    git remote update
    git fetch --all --prune 
    git branch -r --list *$1* | xargs git checkout --force
    

    save this as switchbranch.sh

    Then use it from the terminal ./switchbranch.sh PRJ-1234

提交回复
热议问题