Moving a Commit to a Different Branch

In this episode, we're going to move a commit from one branch to another, existing branch.

Transcript
Moving a Commit to a Different Branch

In this episode, we’re going to move a commit from one branch to another, existing branch. The problem we’re solving here is very common: you make a commit and quickly realize that you were on the wrong branch. You should have made the commit on a different branch, most likely a feature branch.

Let’s look at a practical scenario. This “Newsletter signup page” commit seems like it should have been made on its corresponding feature branch. The first step in order to move this commit over is to checkout the correct branch, in this case “feature/newsletter”.

Then we can select master and cherry-pick that commit - simply by dragging the commit and dropping it onto the feature branch in the sidebar.

So we now have that commit also in our feature branch, where it actually belonged in the first place.

Finally, we need to clean up our master branch: a double-click to check it out, and then we can use reset to remove that unwanted commit from the history in this branch.

Voila: master does not contain this commit anyomer, but "feature/newsletter" does - just as it should be!