How to Change a Commit Message in Git After Push

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:

  1. In the list, change pick to reword next to the commit you want to change.
  2. Save and exit.
  3. Git will prompt you to edit the message.

After editing, force push again:

git push --force

🧠 Summary

TaskCommand
Change last commit messagegit commit --amend -m "New message"
Rebase to edit older messagesgit rebase -i HEAD~n
Push updated commitsgit 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.

Sharing Is Caring:

Leave a Comment