Git: Not able to checkout after fetch
Nov 5, 2020
Sometimes, it happens that after fetching a branch, you still not able to checkout the newly fetched branch. The branch is likely present in more than one remote. (You can confirm this with git branch --list --remotes '*/feature-branch'
.) git checkout
only creates branches like that if they’re unambiguous. From git-checkout(1)
:
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 checkout -b <branch> --track <remote>/<branch>
So you’ll need to do that instead:
git checkout -b feature-branch --track origin/feature-branch