简体   繁体   English

从远程开发分支创建本地分支

[英]creating local branch from remote develop branch

I want to create a local and a remote branch named test from the develop branch on origin.我想从源上的开发分支创建一个名为 test 的本地和远程分支。 However, even though my current local branch is tracking origin/develop when I checkout the new branch it takes origin/master.但是,即使我当前的本地分支在我签出新分支时跟踪 origin/develop 它也需要 origin/master。 Therefore, I have to follow the steps below to get a test branch on both remote and local.因此,我必须按照以下步骤在远程和本地获取测试分支。

git checkout -b test ( By default it picks origin/master though my current branch tracks origin/develop)
git fetch origin
git reset --hard origin/develop 
git push -u origin test 

According to the documentation根据文档

git checkout -b test --track origin/develop

should do the trick.应该做的伎俩。


As extra goodies, if you want to create a local branch to track a remote branch with the same name, you can be lazy an omit the -b option作为额外的好处,如果你想创建一个本地分支来跟踪同名的远程分支,你可以偷懒省略-b选项

git checkout --track origin/develop

will create and checkout a local branch named develop , thus being equivalent to将创建并签出一个名为develop的本地分支,因此相当于

git checkout -b develop --track origin/develop

From the doc从文档

As a convenience, --track without -b implies branch creation.为方便起见,不带 -b 的 --track 意味着创建分支。

[...] [...]

If no -b option is given, the name of the new branch will be derived from the remote-tracking branch.如果没有给出 -b 选项,新分支的名称将从远程跟踪分支派生。

Starting with Git 2.23 , you can also use:Git 2.23开始,您还可以使用:

git switch -t origin/<branch>

It creates and checkouts to a new local branch named <branch> tracking the remote origin/<branch> .它创建并签出到一个名为<branch>的新本地分支,跟踪远程origin/<branch>

More details on the documentation .有关文档的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM