Solution to error when git switches branches (error: pathspec 'master' did not match any file(s) known to git.)

git error when switching branches

Switch branches:

[root@git my_code]# git checkout master

The following error is generated:

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

Solution:

1. Check the branch status:

[root@git my_code]# git branch -a
Insert image description here

2. If you don’t see the branch you want, get all branches first:

[root@git my_code]# git fetch
Insert image description here

3. Check the branch situation again at this time

[root@git my_code]# git branch -a
Insert image description here
You can see that the branch we want is displayed

4. Switch branches

[root@git my_code]# git checkout master
[root@git my_code]# git branch --list
Insert image description here
At this point, the branch switch is successful and the problem is solved.

Guess you like

Origin blog.csdn.net/weixin_44178770/article/details/124830279