我通过git fetch origin name-of-branch:refs/remotes/name-of-branch
获取远程分支。
我使用git checkout name-of-branch
我处于一个独立的头状态。我现在可以使用git checkout -b some-branch-name
到达命名分支。有没有办法在一个命令中将远程分支签出到命名分支(甚至同名)?
如果我使用git checkout -b name-of-remote-branch
(即使用相同的名称),那么请检查另一个分支,然后再次检查该分支git checkout name-of-remote-branch
,我得到
warning: refname 'name-of-remote-branch' is ambiguous.
但是,如果我首先使用git pull
然后使用checkout:
Branch name-of-pulled-branch set up to track remote branch name-of-pulled-branch from origin
我认为,对于获取的分支而言,我遇到的很多麻烦都与不设置为跟踪远程分支的事实有关。为什么会这样,有没有办法检查取出的分支并将其设置为跟踪远程分支,就像我使用git pull
一样?
答案 0 :(得分:2)
你想:
git fetch origin name-of-branch:refs/remotes/name-of-branch
git checkout -b some-branch-name name-of-remote-branch --track
这将设置跟踪,以便git pull / push将Just Work。