gitgithubgithub-for-windows

How do I switch a branch in Git?


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

Solution

  • 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