Create new branch based on current branch to work on a new feature
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?
git
I want the new branch to be a local branch, and a copy of the current branch (ie, the new branch's HEAD should be the same as the current HEAD).
Question differentiation:
(Nitpick) I think you're having the wrong links for the "question differentiation" section. There are 4 links but only 2 questions.
– user202729
Sep 1 at 16:32
@user202729 The bottom two links were initially marked as duplicates as mentioned in the meta discussion linked in my previous comment. I'll edit the differentiation to make that more obvious.
– Tom Hale
Sep 2 at 4:43
1 Answer
1
TL;DR:
To create and start work on a new branch called FEATURE, you do:
FEATURE
git checkout -b FEATURE
Detailed explanation
To create a branch called FEATURE:
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:
checkout
git checkout FEATURE
(You can see the current branch marked with a * in the output of git branch --list.)
*
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.
git checkout -b FEATURE
checkout
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Reopen queue reviewers: you may wish to read the meta.so discussion of this question here.
– Tom Hale
Sep 1 at 10:15