git fetch工作但checkout分支不起作用

ami*_*o21 0 git

我正在尝试checkout从我的upstream远程仓库获取的分支,但它似乎不起作用.

$ 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.
Run Code Online (Sandbox Code Playgroud)

难道我做错了什么?

Ry-*_*Ry- 8

分支可能存在于多个远程中.(您可以使用git branch --list --remotes '*/feature-branch'.确认这一点.)git checkout如果它们是明确的,则只创建类似的分支.来自git-checkout(1):

如果<branch>找不到但是在一个<remote>具有匹配名称的远程(称为)中确实存在跟踪分支,则视为等效于

$ git checkout -b <branch> --track <remote>/<branch>
Run Code Online (Sandbox Code Playgroud)

所以你需要这样做:

git checkout -b feature-branch --track upstream/feature-branch
Run Code Online (Sandbox Code Playgroud)