Moving a Commit to a New Branch
In this episode, we're going to move a commit to a new branch.
Transcript
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!
Course outlineEpisode 11 of 17
- Discarding All Local Changes in a File
- Restoring a Deleted File
- Discarding Chunks / Lines in a File
- Discarding All Local Changes
- Fixing the Last Commit
- Reverting a Commit in the Middle
- Resetting to an Old Revision
- Resetting a File to an Old Revision
- Recovering Deleted Commits
- Recovering a Deleted Branch
- Moving a Commit to a New Branch
- Moving a Commit to a Different Branch
- Editing Old Commit Messages
- Deleting Old Commits
- Squashing Multiple Commits into One
- Adding a Change to an Old Commit
- Splitting / Editing an Old Commit