Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: Commit the currently uncommitted work in progress in the current branch to a new branch

Occasionally I find my self in the following situation: I am working on branch (say master) and I am editing some files, but when it comes the time for a commit I realize that I would prefer to commit to a new branch (say experimental). In other words, the old branch (master) must remain intact and a new branch should be created that will look like:

.. -- master -- new commit

What is the easiest way to do that?

Currently, I commit to old branch, then create the new branch and finally reset the old branch. But that's really ugly.

like image 878
tros443 Avatar asked Oct 20 '11 04:10

tros443


1 Answers

git checkout -b branch       # create new branch out of current head
git add <files>              # the changes you had done in your working directory will be carried over
git commit -m "message"      # commit!
like image 73
manojlds Avatar answered Oct 16 '22 16:10

manojlds