Git: terminate the current work in progress in the current branch to a new branch

Sometimes I find myself in the following situation: I work on a branch (say, a wizard), and I edit some files, but when it comes time to commit, I understand that I would prefer to transfer a new branch (say, experimental). In other words, the old branch (master) should remain intact and a new branch should be created that would look like this:

.. -- master -- new commit 

What is the easiest way to do this?

I am currently committing an old branch, then creating a new branch and finally reset the old branch. But it is really ugly.

+6
source share
3 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! 
+4
source

A little easier if you first create a new branch:

 $ git checkout -b new_branch $ git commit 
+1
source

Another possibility is for you to go ahead and pass them to the master branch, and then disconnect the other branch from the new HEAD (say feature ). Once this is done, you can git reset master to a position before committing.

0
source

Source: https://habr.com/ru/post/899670/


All Articles