Home » Softwares » Git » Create a New Git Branch with Uncommited Code

Create a New Git Branch with Uncommited Code

If you started doing some code modification but you realize that you should have done these modifications in a branch instead of directly into the branch you did the modification, you can move all files into a new branch. The command is checkout with the parameter -b which create the branch if this one does not exist.

git checkout -b NewBranch
git add .

The git add . simply add all uncommited file into the staged area.

Other possibility exist like using git stash to move uncommited code into a temporary place and unstash into another branch.

git stash
git checkout NewBranch
git stash apply

If you like my article, think to buy my annual book, professionally edited by a proofreader. directly from me or on Amazon. I also wrote a TypeScript book called Holistic TypeScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.