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

 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


Steps:

1. git remote -v
2. git remote remove origin
3. git remote add origin git@github.com:company/project_name.git
4. git pull --ff-only
5. git branch --set-upstream-to=origin/current_branch