Back to Articles
Git Jul 25, 2026 3 min read

How to Rename a Git Commit (Even After Pushing)

Learn how to rename the latest or an older Git commit using git commit --amend and interactive rebase. This guide also explains when and why to use git push --force-with-lease.

How to Rename a Git Commit (Even After Pushing)

Mistyped a commit message? No worries. Git allows you to rename commit messages whether it's the latest commit or an older one.

This guide covers both scenarios.


Rename the Last Commit

If the commit you want to rename is the most recent one, simply amend the commit message.

Step 1: Update the commit message

git commit --amend -m "Your new commit message"

Step 2: Push the updated commit

If the commit has already been pushed to GitHub, you'll need to force-push the updated history.

git push --force-with-lease

Why --force-with-lease instead of --force?

--force-with-lease is safer because it prevents you from accidentally overwriting changes that someone else has pushed to the remote repository.


Rename an Older Commit

If the commit is not the latest one, use an interactive rebase.

Step 1: Start an interactive rebase

git rebase -i HEAD~5

Replace 5 with the number of recent commits that includes the commit you want to rename.

For example, if you want to rename the second-last commit:

git rebase -i HEAD~2

Step 2: Mark the Commit for Editing

Git will open your default editor with something like:

pick abc1234 Add authentication
pick def5678 Update README

Change the commit you want to rename from pick to reword.

reword abc1234 Add authentication
pick def5678 Update README

Save and close the editor.


Step 3: Update the Commit Message

Git will reopen your editor with the selected commit message.

Replace it with your new message, then save and close the editor.


Step 4: Complete the Rebase

If Git encounters conflicts, resolve them and continue:

git rebase --continue

If there are no conflicts, Git will finish automatically.


Step 5: Push the Updated History

If the renamed commit had already been pushed to GitHub, update the remote branch with:

git push --force-with-lease

Example

Suppose your commit history looks like this:

A ── B (Wrong commit message) ── C (Latest commit)

You want to rename B.

Run:

git rebase -i HEAD~2

Change:

pick B Wrong commit message
pick C Latest commit

To:

reword B Wrong commit message
pick C Latest commit

Save, edit the commit message, and finish the rebase.

Finally, push the updated history:

git push --force-with-lease

Summary

ScenarioCommand
Rename the latest commitgit commit --amend -m "New message"
Rename an older commitgit rebase -i HEAD~N
Push rewritten historygit push --force-with-lease

Final Thoughts

Renaming commit messages is a common Git task. For the latest commit, git commit --amend is the quickest solution. For older commits, an interactive rebase gives you full control over your commit history.

When rewriting commits that have already been pushed, always prefer:

git push --force-with-lease

instead of:

git push --force

It's the safer option and helps prevent accidentally overwriting changes on the remote repository.

Share this article

Dabananda Mitra

Dabananda Mitra

Software Engineer specializing in scalable backend systems and minimal, effective API design.

Comments

Loading comments...