Git & GitHub Mastery: Workflows & CI/CD
Back to Real-World Git Workflows

Interactive Rebase

Rewrite your branch's history: squash, edit, reorder, drop commits before sharing. The history-cleanup superpower. FIND_VIDEO: search 'git interactive rebase tutorial squash' — recommended channel: Fireship / Atlassian. Aim for 10 min or under.

5 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Assess History Scope — Inspect the current commit history using `git shortlog` to define the goal of the cleanup.
  2. Create Safety Branch — Check out a new, isolated branch derived from the feature branch to allow for easy rollback.
  3. Initiate Interactive Rebase — Execute `git rebase -i HEAD~n` to open the editor and target the specific range of commits.
  4. Apply Squash Instructions — Change the instruction from `pick` to `squash` for all commits that should be merged into the preceding commit.
  5. Rewrite Commit Message — Edit the second editor window to create a single, clean, and descriptive summary for the consolidated commit.
  6. Verify and Merge — Use `git diff` to confirm code integrity before merging the newly cleaned branch into the main target branch.
PDF notes

Frequently asked questions

Why is interactive rebase considered a destructive action?

It rewrites history by creating entirely new commit SHAs, which can cause conflicts if the history has already been shared with others.

How does the 'squash' directionality work?

A commit marked 'squash' collapses its changes *upwards* into the commit listed immediately before it in the interactive editor.

What is the purpose of running `git diff` after rebase?

It validates that the history cleanup did not accidentally alter the final code state, ensuring the rebased branch is functionally identical to the original.

Can I use rebase to combine commits that are not sequential?

Yes, but you must use the rebase editor to reorder the commits first so that the ones you want to squash are adjacent.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.