How to interactive rebase in Git

Interactive rebasing is essential for cleaning up commit history, combining related commits, and preparing a polished commit sequence before merging to main branches. As the creator of CoreUI with over 25 years of development experience managing Git repositories since the early 2000s, I’ve used interactive rebase extensively to maintain clean, readable project history across our open-source repositories. The most powerful approach is using git rebase -i with a base commit to interactively edit, squash, reorder, or delete commits in your branch. This method provides complete control over commit history while maintaining the logical flow of changes for better code review and project maintenance.

Use git rebase -i HEAD~n to interactively rebase the last n commits and modify your commit history.

# Interactive rebase for the last 3 commits
git rebase -i HEAD~3

# Or rebase against a specific branch
git rebase -i main

Interactive rebase opens an editor showing commits with action keywords: pick (keep commit), reword (edit message), edit (modify commit), squash (combine with previous), fixup (squash without message), drop (remove commit), and exec (run command). You can reorder lines to change commit sequence, change action words to modify commits, or delete lines to remove commits entirely. After saving, Git guides you through each step, allowing you to edit commit messages, modify file changes, or resolve conflicts as needed.

Best Practice Note:

This is the workflow we use in CoreUI development to maintain clean, professional commit history before merging feature branches. Never rebase commits that have been pushed to shared repositories, as this rewrites history and can cause conflicts for other developers working on the same branch.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to Redirect to a New URL Using JavaScript Redirect Techniques
How to Redirect to a New URL Using JavaScript Redirect Techniques

How to loop inside React JSX
How to loop inside React JSX

How to Achieve Perfectly Rounded Corners in CSS
How to Achieve Perfectly Rounded Corners in CSS

How to Convert a Map to an Array in JavaScript
How to Convert a Map to an Array in JavaScript

Answers by CoreUI Core Team