有人推了“新功能”分支到共享回购:现在如何在Git中签出远程分支?
git push -u new_feature_branch
,我想,以测试新的功能,我的本地机器上创建这个分支的副本。
最简单的方法是什么? (我需要fetch
/pull
checkout
前?)
有人推了“新功能”分支到共享回购:现在如何在Git中签出远程分支?
git push -u new_feature_branch
,我想,以测试新的功能,我的本地机器上创建这个分支的副本。
最简单的方法是什么? (我需要fetch
/pull
checkout
前?)
我一般觉得没必要用git fetch
。 git pull
就足够了。 git pull
将使您的存储库与远程同步。然后new_feature_branch将可用。
git checkout new_feature_branch
会注意到分支的来源并为您创建一个新的本地跟踪分支并切换到该分支。
git pull
git checkout new_feature_branch
git pull == git fetch + git merge – 2017-10-24 09:17:04
您需要获取上游变化,使本地资源库包括相关对象(git fetch --all
或git fetch <remote>
)。
之后,您可以执行使用git checkout <branch>
结帐(如果你想明确地做到这一点,你可以键入git checkout -b <branch> <remote>/<branch>
;本地名不必是相同的遥控器)。如果您还没有该名称的本地分支,它将检出远程分支并对其进行跟踪。
作为替代方案,您可以使用git pull <remote> <branch>
,但是这将使用默认设置将远程分支合并到当前,这可能不是您想要的。
我想知道为什么这个答案说你必须使用'fetch -all',而最上面的答案只是提到'fetch'。哪一个? – 2017-07-18 13:27:00
@PetriSirkkala答案并不是说你必须使用'--all'。 'fetch --all'表示获取所有的遥控器(如果你有更多的例如'origin')。 – 2017-12-11 14:38:54
做到这一点,最简单的方法是:
git fetch
git checkout -t origin/new_feature_branch
这只是初步完成。从现在开始,您可以继续与分支机构一起工作,就像您为其他人使用一样。
git fetch && git checkout new_feature_branch
如果你有时间,你可以请看看这个问题。 http://stackoverflow.com/questions/20634111/magento-error-when-disable-module – 2015-11-12 08:24:16
可能被复制。 http://stackoverflow.com/questions/1783405/checkout-remote-git-branch – 2015-09-22 22:02:17
可能重复的[如何检查远程Git分支?](https://stackoverflow.com/questions/1783405/how- do-i-check-out-a-remote-git-branch) – SudoRahul 2017-06-15 10:15:02