Article directory
foreword
Recently, I assisted the group next door to solve some problems and audit the code. Because I did not submit the code, an error occurred when switching to their new branch.
question
switch branch locally
git checkout xxx
report error
error: pathspec 'XXX' did not match any file(s) known to git
solve
1. View all local branches
Check whether there are new branches created by colleagues in all local branches
git branch -a
2. Get all branches
If you don't see it, then do the following, this step is to get all branches
git fetch
3. After execution, you will see a prompt
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
Unpacking objects: 100% (4/4), 1.06 KiB | 90.00 KiB/s, done.
From codeup.aliyun.com:5eeb0689892c58bb7c394ab5/pxb/pxb-fronted
* [new branch] XXX -> origin/XXX
4. Switch to remote colleagues branch
git checkout origin/XXX
hint
Note: switching to 'origin/XXX'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at dc877cd XXX
5. Create a new branch and switch to a colleague
Now you can see that your own branch is a string of numbers and letters. At this time, create a new branch and switch to a colleague's branch
git checkout -b XXX
6. Associate with remote colleagues branch
git branch -u origin/XXX XXX
7. Now we can execute git pull
git pull