Learning Git: What is Interactive Rebase?

Learning Git: What is Interactive Rebase?

Advanced Git Tutorial Video

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!

Download GitKraken Free

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: 

  • Pick a Commit with Interactive Rebase 

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. 

Git pick interactive rebase
  • Reword a Commit with Interactive Rebase

The Reword action allows you to edit the commit message. 

rewording a commit interactive rebase
  • Squash Commits with Interactive Rebase

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

squash commits interactive rebase
  • Drop Commits with Interactive Rebase

The Drop action removes a commit from the branch. 

drop commits interactive rebase
  • Reorder Commits with Interactive Rebase

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

reorder commits interactive rebase

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.

interactive-rebase in GitKraken

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.

rewording commits interactive rebase gitkraken

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. 

squashing interactive rebase gitkraken

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

reordering commits interactive rebase gitkraken

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. 

Stay on the cutting edge of software development by getting innovative tips, trends and stories delivered to your inbox every month!

Agile project management software
Plan, develop, review, and ship fast

Visit Axosoft.com

Legendary suite of developer tools
GitKraken Git GUI, Boards & Timelines

Visit GitKraken.com