2 min episode 11 of 17
In this episode, we’re going to move a commit to a new branch. The problem we’re solving here is a true classic: you’ve finished some work and committed it proudly to the Git repository. Only to notice that you were on the wrong branch and that actually, you should have created a new branch for this work.
Let’s take a look at a practical example. The problem here is quite obvious: a commit named “Start new login feature” should probably not happen on the master branch - but on its own, separate feature branch. Let’s fix this!
First, we should create that new feature branch. To base it on our “master” branch, simply drag and drop it in the sidebar. Awesome - we now have a new branch that contains that new commit.
What’s left to do is to clean up the master branch. Since master is still checked out, we can simply use “reset” to remove that unwanted commit from that branch.
And that’s it: now, “master” does not have that feature commit anymore - but our shiny new "feature/login" branch does! Just like we’d expect it!