Amending and Fixing Work-in-Progress Commits
You'll learn when and how to use git commit --amend to polish your most recent commit before sharing it with your team.
The Problem: Oops, I Forgot Something
You just made a commit, then immediately realize you forgot to include a file, made a typo in the commit message, or want to add one more small fix. Creating a whole new commit for these tiny adjustments clutters your history with messages like "oops" or "fixed typo"—not exactly professional.
The Solution: Amending
git commit --amend lets you replace your most recent commit with a new one. Think of it like editing a draft email before hitting send—you're not creating a second email, you're perfecting the first one.
When to Use Amend
- Before pushing: Only amend commits that haven't been pushed to a remote repository yet
- Fixing typos in your commit message
- Adding forgotten files to the staging area
- Making small corrections that logically belong with the previous commit
How It Works
# Make your initial commit
git commit -m "Add user authentication"
# Oops, forgot a file!
git add forgot_this_file.py
git commit --amend
# Or just fix the message without adding files
git commit --amend -m "Add user authentication module"
When you amend, Git creates a new commit object that replaces the old one. Your working changes get incorporated, and you can rewrite the message.
The Golden Rule
Never amend commits that you've already pushed to a shared remote. Other developers may have based work on that commit, and changing it causes confusion and conflicts.
Key Takeaway: Use git commit --amend to polish work-in-progress commits before pushing—it keeps your history clean without creating trivial "fix" commits.