Mistyped a commit message or want to clarify it? While Git doesn’t let you directly edit pushed commits like editing a document, you can rewrite history carefully using Git’s powerful tools.
This guide walks you through how to change a commit message after you’ve pushed it to a remote repository.
⚠️ Important Warning
Changing commits after pushing rewrites history, which can cause issues for other collaborators. Only do this if:
- You are the only one working on the branch, OR
- Everyone else is informed and agrees to force-pull updates
🛠️ Step 1: Amend the Last Commit Message
To change the most recent commit message:
git commit --amend
You’ll be prompted to edit the message in your default text editor. Update it, save, and exit.
Alternatively, do it inline:
git commit --amend -m "New commit message"
📤 Step 2: Force Push the Updated Commit
After amending the message, you need to force push the change to the remote:
git push --force
Or:
git push -f
This tells Git to overwrite the commit on the remote repository with your updated one.
🔁 What If I Want to Edit an Older Commit?
Use an interactive rebase:
git rebase -i HEAD~n
Replace n
with how many commits back you want to edit.
Then:
- In the list, change
pick
toreword
next to the commit you want to change. - Save and exit.
- Git will prompt you to edit the message.
After editing, force push again:
git push --force
🧠 Summary
Task | Command |
---|---|
Change last commit message | git commit --amend -m "New message" |
Rebase to edit older messages | git rebase -i HEAD~n |
Push updated commits | git push --force |
✅ Conclusion
Changing commit messages after a push is possible, but must be done with care. Use --amend
or interactive rebase to update history, and always force push to reflect the changes remotely. When collaborating, communicate clearly before rewriting shared history.