Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 832
Tom Hale Avatar asked Oct 12 '17 10:10

Tom Hale


1 Answers

If you say

$ git checkout -b myFeatureBranch anotherBranch

It'll create myFeatureBranch off of anotherBranch. But if you say

$ git checkout -b myFeatureBranch

It'll create myFeatureBranch off of the current branch.

like image 186
doctorram Avatar answered Nov 10 '22 03:11

doctorram