This guide will explain about:
- When Does “error: pathspec ‘…’ did not match any file(s) known to git” Occur?
- How to Resolve the “error: pathspec ‘…’ did not match any file(s) known to git” Error?
When Does “error: pathspec ‘…’ did not match any file(s) known to git” Occur?
To mention error encountered mainly by developers when they want to access a branch that does not exist in the local branch.
How to Resolve the “error: pathspec ‘…’ did not match any file(s) known to git” Error?
To resolve the above-stated error, developers are required to create the particular branch first and then switch to it by utilizing the “git checkout -b <branch-name>” command. Follow the below-stated steps to view the cause of the previously discussed error and then resolve it.
Step 1: Navigate to Git Root Directory
First, go to the Git root directory by executing the cd“ command:
Step 2: Checkout to Local Branch
Then, run the “git checkout” command to switch to the desired local branch:
Here, the “beta” is the name of the local branch. However, it shows the “pathspec ‘beta’ did not match any file(s) known to git” error, which means the specified branch does not exist in the list:
To resolve the above-stated error, users need to create a new branch first.
Step 3: Generate and Switch Branch
To create and immediately navigate to the specified branch through the following command:
In the above-listed command, the “-b” option represents the branch:
According to the below-provided output, the new branch is generated and switched successfully.
Step 4: Verify Newly Created Branch
Lastly, to ensure whether the new branch is created or not, run the following command:
As you can see, the new branch exists in the list of local repositories:
That’s all! We have provided the solution for the discussed error.
Conclusion
To “pathspec ‘…’ did not match any file(s) known to git” error occurs when users want to access the branch which does not exist in the local branch. To resolve this error, they need to execute the “git checkout -b <branch-name>” command. This guide provided the easiest way to resolve the discussed pathspec error.