Learning Git: What is Interactive Rebase?

GitKraken
4 min readMar 20, 2020

What is interactive rebase in Git? And how does one rebase interactively? 🤔In this advanced Git tutorial, we will go over everything you need to understand what interactive rebase is, how to confidently utilize the feature in GitKraken, and an example of how interactive rebase works in Git.

What does it mean to rebase in Git?

Before we get into interactive rebase, let’s do a quick refresher on rebasing in Git. As you may recall, rebasing takes the commits from one branch and places them onto a different branch.

Learn about the differences between merging and rebasing in this intermediate Git tutorial video.

Typically, this process happens in one step and the commit order and commit messages carry over to the new branch. But what if you could customize how the commits are rebased? What if you wanted to change some elements before they’re placed onto the new branch?

This is where interactive rebase comes in.

What is Interactive Rebase?

If you haven’t already started using the GitKraken Git GUI to make interactive rebases easier, download it for free now!

What actions can you perform with Interactive Rebase in Git?

Interactive rebase allows you to take special actions for each commit. The most common Git actions users may choose to perform during an interactive rebase include:

The Pick action in Git takes the commits from one branch and places them onto the last commit of another branch. This is the only action that is performed when doing a (non-interactive) rebase in Git.

The Reword action allows you to edit the commit message.

The Squash action takes the changes from one commit and adds those changes to the previous commit.

The Drop action removes a commit from the branch.

The Reorder action allows you to change the order of your commits on the new branch.

Interactive rebase in Git makes it easy to clean up your commits before they get rebased, or moved onto another branch. Not only does this help make your project history easier to read, it can also help prevent future conflicts.

Interactive Rebase in GitKraken

Let’s see how interactive rebase works in GitKraken.

To perform an interactive rebase in GitKraken, start by dragging-and-dropping one branch onto a target branch. You can also access the option to initiate an interactive rebase by right-clicking.

You will then be directed to the interactive rebase screen and, by default, each commit will be set to pick. However, you can choose to perform a number of actions before you click to start the rebase.

For example, you may click to reword the commit messages, or change the commit description.

You can also choose to squash commits, which will not only combine the changes from the squashed commits, but will also combine the commit messages.

Furthermore, you can choose to drop a commit to completely remove it, or drag-and-drop commits to reorder them.

If you want to make any changes to your selections, you can click the Reset button to start over, or Cancel Rebase to exit the interactive rebase screen.

If things look good to go, click the Start Rebase button and see your commit graph update accordingly.

ProTip: you will only be able to access interactive rebase via drag-and-drop in GitKraken if the following situations apply:

  • No merge commits are present on the branch you’re rebasing.
  • The two branches share a common ancestor.
  • Neither branch has the repo’s initial commit.
  • You’re not attempting to rebase a parent branch onto a child (ie master onto a feature branch).

Not too bad, right? If you liked this video, please consider subscribing to the GitKraken YouTube channel where you can watch Git tutorials for all experience levels, and checkout our Learn Git Center for additional educational resources.

Maximize the productivity of your workflow with interactive rebase and the GitKraken Git GUI. Download GitKraken Free

Originally published at https://blog.axosoft.com on March 20, 2020.

--

--

GitKraken

Creators of the world's most powerful suite of Git tools: GitKraken Client, GitKraken CLI, Git Integration for Jira, GitLens for VS Code & IntelliJ (soon).