0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Lesson

Interactive Rebase and Amending

Learn to rewrite history with `git rebase -i` for cleaner commits and use `git commit --amend` to modify the last commit.

Interactive Rebase and Amending is a free Git Advanced: Monorepo, Submodules & Workflows lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Git Advanced: Monorepo, Submodules & Workflows learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Clean Up Your Git History

Git history gets messy — a forgotten file, a typo'd message, ten tiny commits that should be one. Git lets you rewrite history to clean it up.

Amending Your Last Commit

git commit --amend fixes your most recent commit: change the message, add forgotten files, or tweak content. It replaces the last commit with a tidier one.

Amending a Commit Example

Forgot a file right after committing? Stage it, then git commit --amend folds it into the last commit. Here's the flow.

# 1. Make some changes and commit
echo "Initial content" > file1.txt
git add file1.txt
git commit -m "Add file1"

# 2. Realize you forgot file2.txt
echo "More content" > file2.txt
git add file2.txt

# 3. Amend the last commit to include file2.txt
git commit --amend --no-edit

Introducing Interactive Rebase

Need to fix commits further back, not just the last one? Interactive rebase (git rebase -i) is a full editor for a series of commits.

Getting Started with Rebase -i

Start an interactive rebase by naming a commit before your target range. To edit the last three commits, use HEAD~3.

git rebase -i HEAD~3

Rebase Commands: Pick, Reword, Squash

The rebase editor lists commits with commands you can swap: pick keeps it, reword edits the message, squash/fixup merge it up, edit pauses to amend.

Rewording a Commit Message

To change an older commit's message, switch its line from pick to reword in the editor. Git then prompts you for the new message.

# Original rebase editor content:
# pick 8a9b3c4 Add initial feature
# pick d1e2f34 Fix typo in docs

# Change 'pick' to 'reword' for the first commit:
# reword 8a9b3c4 Add initial feature
# pick d1e2f34 Fix typo in docs

Squashing Commits Together

Got several small commits that belong together? squash merges them into one meaningful commit — change the lines below pick to squash.

# Original commits:
# pick abc1234 Add user registration form
# pick def5678 Add validation for email field
# pick ghi9012 Fix styling on form

# To squash the last two into the first:
# pick abc1234 Add user registration form
# squash def5678 Add validation for email field
# squash ghi9012 Fix styling on form

Editing an Older Commit

The edit command pauses the rebase at a specific commit. Make changes, git add, git commit --amend, then git rebase --continue.

When to Be Careful with Rewriting

Rewriting changes commit IDs — safe for local-only commits. Never rewrite history that's already pushed and shared; it wrecks your collaborators' work.

Quick Check: History Rewriting

You've made a commit with the message "Fix bug". You then realize you forgot to include one small file in that commit. What is the most appropriate Git command to fix this, assuming you haven't pushed the commit yet?

Recap: Cleaner Commits

Recap: git commit --amend fixes the last commit, while git rebase -i rewrites a series — reword, squash, fixup, or edit. Just be careful on shared branches.

Frequently asked questions

Is the “Interactive Rebase and Amending” lesson free?

Yes — the full text of “Interactive Rebase and Amending” is free to read here on the web, and the Git Advanced: Monorepo, Submodules & Workflows course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Git Advanced: Monorepo, Submodules & Workflows course, upgrade to CoddyKit PRO.

What will I learn in “Interactive Rebase and Amending”?

Learn to rewrite history with `git rebase -i` for cleaner commits and use `git commit --amend` to modify the last commit. You practise Git Advanced: Monorepo, Submodules & Workflows with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Git Advanced: Monorepo, Submodules & Workflows?

No prior experience is required. Git Advanced: Monorepo, Submodules & Workflows on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Interactive Rebase and Amending” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Git Advanced: Monorepo, Submodules & Workflows lesson?

Yes. Every Git Advanced: Monorepo, Submodules & Workflows lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Interactive Rebase and Amending
  2. Stashing and Cherry-picking Changes
  3. Reflog for Recovery
  4. Bisect: Hunting Down Bad Commits
← Back to Git Advanced: Monorepo, Submodules & Workflows