Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git fetch works but checkout branch doesn't work

Tags:

git

I'm trying to checkout a branch that I've just fetched from my upstream remote repo but it doesn't seem to work.

$ git fetch upstream
Fetching upstream
From github.com:group/repo
* [new branch]      feature-branch -> upstream/feature-branch

$ git checkout feature-branch
error: pathspec 'feature-branch' did not match any file(s) known to git.

Am I doing something wrong?

like image 741
amigo21 Avatar asked Nov 21 '25 09:11

amigo21


1 Answers

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 upstream/feature-branch
like image 100
Ry- Avatar answered Nov 24 '25 00:11

Ry-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!