SoFunction
Updated on 2025-04-14

Git error error:pathspec ‘XXX’did not match any file(s) known to git problem and solution process

Problem recurs

① Switch to the newly created branch of a colleague in the local branch:

git checkout xxx

② Error:

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

Solution

① Check whether there are newly created branches by colleagues in all local branches:

git branch -a

② If you don't see it, then do the following, and this step is to get all branches:

git fetch

③ After executing, you will see this 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 :5eeb0689892c58bb7c394ab5/pxb/pxb-fronted
 * [new branch]      XXX -> origin/XXX

④ Switch to the remote colleague 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 to false

HEAD is now at dc877cd XXX

⑤ You can now see that your branch is a string of numeric letters. At this time, create and switch to the branch of your colleague:

git checkout -b XXX

⑥ Now you need to associate with the remote colleague branch:

git branch -u origin/XXX XXX

⑦ At this time, we execute git pull to see what feedback:

git pull
Already up-to-date.

⑧ At this time, if you modify the code, the operation you need to do is:

View modification status:git status -s
Add to local temporary storage area:git add ./
Add to local repository:git commit -m "[ADD]A new feature"
Add to remote repository,There will be one more branch in the remote repositoryxxx:git push origin xxx

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.