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:





Reopen queue reviewers: you may wish to read the meta.so discussion of this question here.
– Tom Hale
Sep 1 at 10:15





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

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ