Create new branch based on current branch to work on a new feature

£可爱£侵袭症+ 提交于 2020-06-24 17:55:09

问题


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

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).


Question differentiation:

  • 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.

回答1:


TL;DR:

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

git checkout -b FEATURE

Detailed explanation

To create a branch called FEATURE:

git branch FEATURE

However, this does not change your current branch.

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

git checkout FEATURE

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

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.



来源:https://stackoverflow.com/questions/46706821/create-new-branch-based-on-current-branch-to-work-on-a-new-feature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!