How to use interactive rebase in Git

Using interactive rebase in Git enables precise commit history editing for cleaner project timelines, squashed commits, and organized development workflows. As the creator of CoreUI with over 11 years of Git experience in enterprise development, I’ve used interactive rebase extensively to maintain clean commit histories in large-scale projects. From my expertise, the most effective approach is using interactive rebase to squash related commits, fix commit messages, and reorder changes before merging feature branches. This technique ensures professional commit histories that clearly communicate project evolution and facilitate easier code reviews.

Use interactive rebase to edit, squash, reorder, and clean up commit history before sharing changes with the team.

# View recent commit history
git log --oneline -5

# Start interactive rebase for last 3 commits
git rebase -i HEAD~3

# Interactive editor opens with commit list
# pick abc123 Add user authentication
# pick def456 Fix typo in login form
# pick ghi789 Update authentication tests

# Edit commands (save and close editor):
# pick abc123 Add user authentication
# squash def456 Fix typo in login form
# reword ghi789 Update authentication tests

# For squash: combine commits and edit message
# For reword: edit commit message only
# For edit: pause rebase to modify commit
# For drop: remove commit entirely

# Rebase specific range
git rebase -i main..feature-branch

# Continue after resolving conflicts
git rebase --continue

# Abort rebase if needed
git rebase --abort

# Example: Clean up messy commits
git log --oneline -4
# d1e2f3g WIP: working on feature
# a4b5c6d Fix bug
# 7h8i9j0 More work
# k1l2m3n Add feature implementation

git rebase -i HEAD~4
# squash d1e2f3g WIP: working on feature
# squash a4b5c6d Fix bug
# squash 7h8i9j0 More work
# pick k1l2m3n Add feature implementation

Here git rebase -i HEAD~n starts interactive rebase for the last n commits. The editor shows available commands: pick keeps commits unchanged, squash combines commits with the previous one, reword edits commit messages, edit pauses for modifications, and drop removes commits. The rebase processes commits in order, allowing complete history restructuring.

Best Practice Note:

This is the same approach we use in CoreUI development workflows to maintain clean, professional commit histories that clearly document feature development and bug fixes. Never rebase commits that have been pushed to shared branches, and always use interactive rebase on feature branches before merging to create clear, logical commit sequences.


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