Git errors: cannot checkout branch – error: pathspec ‘branch_name’ did not match any file(s) known to git

Sometimes after repository checkout you can encounter the error trying to switch branches:

git checkout branch_name
error: pathspec ‘branch_name’ did not match any file(s) known to git

To fix that you can remove remote origin and link it again…


This content originally appeared on DEV Community and was authored by Maria Yudina

Sometimes after repository checkout you can encounter the error trying to switch branches:

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

To fix that you can remove remote origin and link it again.
First, check the remote origin:

git remote -v
origin  git@github.com:company/project_name (fetch)
origin  git@github.com:company/project_name (push)

Then remove origin:

git remote remove origin

And add remote origin again with correct path from your repository (copy from GitHub/GitLab/etc.):

git remote add origin git@github.com:company/project_name.git

After that run:

git pull --ff-only

And set upstream to origin branch:

git branch --set-upstream-to=origin/current_branch

After this you should be bale to switch between the branches as usual.


This content originally appeared on DEV Community and was authored by Maria Yudina


Print Share Comment Cite Upload Translate Updates
APA

Maria Yudina | Sciencx (2021-11-14T13:40:58+00:00) Git errors: cannot checkout branch – error: pathspec ‘branch_name’ did not match any file(s) known to git. Retrieved from https://www.scien.cx/2021/11/14/git-errors-cannot-checkout-branch-error-pathspec-branch_name-did-not-match-any-files-known-to-git/

MLA
" » Git errors: cannot checkout branch – error: pathspec ‘branch_name’ did not match any file(s) known to git." Maria Yudina | Sciencx - Sunday November 14, 2021, https://www.scien.cx/2021/11/14/git-errors-cannot-checkout-branch-error-pathspec-branch_name-did-not-match-any-files-known-to-git/
HARVARD
Maria Yudina | Sciencx Sunday November 14, 2021 » Git errors: cannot checkout branch – error: pathspec ‘branch_name’ did not match any file(s) known to git., viewed ,<https://www.scien.cx/2021/11/14/git-errors-cannot-checkout-branch-error-pathspec-branch_name-did-not-match-any-files-known-to-git/>
VANCOUVER
Maria Yudina | Sciencx - » Git errors: cannot checkout branch – error: pathspec ‘branch_name’ did not match any file(s) known to git. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/14/git-errors-cannot-checkout-branch-error-pathspec-branch_name-did-not-match-any-files-known-to-git/
CHICAGO
" » Git errors: cannot checkout branch – error: pathspec ‘branch_name’ did not match any file(s) known to git." Maria Yudina | Sciencx - Accessed . https://www.scien.cx/2021/11/14/git-errors-cannot-checkout-branch-error-pathspec-branch_name-did-not-match-any-files-known-to-git/
IEEE
" » Git errors: cannot checkout branch – error: pathspec ‘branch_name’ did not match any file(s) known to git." Maria Yudina | Sciencx [Online]. Available: https://www.scien.cx/2021/11/14/git-errors-cannot-checkout-branch-error-pathspec-branch_name-did-not-match-any-files-known-to-git/. [Accessed: ]
rf:citation
» Git errors: cannot checkout branch – error: pathspec ‘branch_name’ did not match any file(s) known to git | Maria Yudina | Sciencx | https://www.scien.cx/2021/11/14/git-errors-cannot-checkout-branch-error-pathspec-branch_name-did-not-match-any-files-known-to-git/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.