At the end of the article, we can see the solution directly
The following is the problem handling process, taking switching to the master branch as an example
There are only some local branches. If you want to switch to other remote branches, you will get an error:
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git
$ git checkout origin/master
error: pathspec 'origin/master' did not match any file(s) known to git
Check all the branches and find that there is no branch you want to switch
$ git branch -a
* dev
remotes/origin/dev
Fetch all branches
git fetch --all #fetch all branches
Then git branch - a
finds that there is still no branch to switch, and tries to directly fetch the specified branch
$ git fetch master
fatal: 'master' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Indicates that the branch does not exist. Check the warehouse and find that the branch has not been removed and still exists
Check the file Project path /. Git/config
, and find that remote only adds a single branch
[remote "origin"]
url = http://XXXXXXXXXXX/XXXXXXXXXXX.git
fetch = +refs/heads/dev:refs/remotes/origin/dev
Amend to read
[remote "origin"]
url = http://XXXXXXXXXXX/XXXXXXXXXXX.git
fetch = +refs/heads/*:refs/remotes/origin/*
Once again, fetch branch, successfully solve the problem
$ git fetch --all
Fetching origin
From http://XXXXXXXXXXX/XXXXXXXXXXX
* [new branch] master -> origin/master
$ git branch -a
* dev
remotes/origin/dev
remotes/origin/master
$ git checkout master
Switched to a new branch 'master'
Branch 'master' set up to track remote branch 'master' from 'origin'.