3

I have executed the line below to switch to a new branch created by my teammate:

git checkout with-backend

I'm receiving the error below: error: pathspec 'with-backend' did not match any file(s) known to git

I tried executing this command:

git branch -a

The with-backend branch created by my teammate is not listed. Below is the result listed:

* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
hera
  • 43
  • 5

2 Answers2

3

First, switching branch is done with git switch (since Git 2.23, Q3 2019), not git checkout (which tries to manage both files and branches, making it confusing)

Second, git switch with-backend will work after git fetch because if its "guessing" mode:

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to

$ git switch -c <branch> --track <remote>/<branch>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Make sure you always pull latest changes from repo, before starting to work

git fetch <-- fetches all the latest changes from remote repo

OR

git pull <-- It is one step ahead of git fetch, it fetches remote changes and also merge local branch with remote branch

Keyur Barapatre
  • 237
  • 2
  • 11