根据当前分支创建新分支以使用新功能 [英] Create new branch based on current branch to work on a new feature

查看:74
本文介绍了根据当前分支创建新分支以使用新功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在git中创建新分支以开始使用新功能?

How do I create a new branch in git to begin work on a new feature?

我希望新分支与当前分支重复(即新分支的HEAD应该与当前HEAD相同).

I want the new branch to be a duplicate of the current branch (ie, the new branch's HEAD should be the same as the current HEAD).

问题区分:

  • Create a branch in Git from another branch seems related but is actually about why a branch is fast-forward merged.
  • How do you create a remote Git branch? is about creating a new branch on a remote.

推荐答案

TL; DR:

要在名为FEATURE的新分支上创建并开始工作,请执行以下操作:

To create and start work on a new branch called FEATURE, you do:

git checkout -b FEATURE

详细说明

要创建一个名为FEATURE的分支:

To create a branch called FEATURE:

git branch FEATURE

但是,这不会更改您当前的分支.

However, this does not change your current branch.

然后您可以checkout新创建的分支(这意味着使其成为您当前正在使用的分支:

You can then checkout the newly created branch (which means make to it the branch you're currently working on:

git checkout FEATURE

(您可以在git branch --list的输出中看到带有*标记的当前分支.)

(You can see the current branch marked with a * in the output of git branch --list.)

通常,您要在刚刚创建的分支中开始工作,因此这两个命令的等效快捷键是git checkout -b FEATURE,它会创建一个新分支,然后在其上执行checkout.

Generally you want to start working in the branch you have just created, so the shortcut equivalent for both commands is git checkout -b FEATURE, which creates a new branch, then does checkout on it.

这篇关于根据当前分支创建新分支以使用新功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆