Fixes

How to Change a Git Commit Message (Even After Pushing)

By Admin · Updated · 4 min read · Checked against the official Git docs

To change the message of your most recent commit, run git commit --amend -m "New message". For an older commit, use interactive rebase and mark it reword. If the commit is already pushed, you’ll need to force push afterwards, so read the warning below first.

Quick answer

Last commit, not pushed: git commit --amend -m "New message". Already pushed: same command, then git push --force-with-lease.

Change a Git commit message with git commit --amend

How we tested: every command on this page was run in a real Git repository (Git 2.43) on 18 November 2026, and the output shown is copied from the terminal. Your commit hashes will differ.

Change the last commit message

$ git commit --amend -m 'Add cart'
[main 169d8c2] Add cart
 Date: Wed Nov 18 09:47:00 2026 +0000
 1 file changed, 1 insertion(+)
$ git log --oneline -2
169d8c2 Add cart
9985d17 Add homepage

Leave out -m and Git opens your editor with the old message in it, which is handier for long messages. Amend doesn’t edit the old commit in place; it replaces it with a new one, which is why the hash changes. That detail is what makes pushed commits tricky.

Make sure nothing is staged before you amend, unless you mean to add it. Anything in the staging area goes into the amended commit along with the new message. Check with git status.

Change a message you already pushed

After amending, a normal push is rejected, because your local history and the remote’s no longer match:

$ git push
To /home/sam/remote/shop-site.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to '/home/sam/remote/shop-site.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Don’t follow that hint and run git pull: it would merge the old commit back in and you’d end up with both messages. Force push instead, with the safe flag:

$ git push --force-with-lease
To /home/sam/remote/shop-site.git
 + 169d8c2...e1d085f main -> main (forced update)

--force-with-lease only overwrites the remote if it still has the commit you last saw. If a teammate pushed something in the meantime, it refuses instead of wiping out their work. Plain --force has no such check.

Shared branch? Think twice. Anyone who already pulled the old commit now has history that conflicts with yours. On main or a branch others build on, a typo in a message usually isn’t worth that. On your own feature branch before review, go ahead.

Change an older commit message

Here the typo is in the middle commit:

$ git log --oneline -3
389f2b1 Add checkout
30e78af Fix tpyo in header
35e340f Add cart

Start an interactive rebase that covers it. HEAD~3 means “the last three commits”:

git rebase -i HEAD~3

Your editor opens with one line per commit, oldest first. Change pick to reword (or just r) on the commit you want to fix, save, and close:

pick 35e340f Add cart
reword 30e78af Fix tpyo in header
pick 389f2b1 Add checkout

Git then opens the editor again with that commit’s message. Fix it, save, close. Here’s the result from our test repo:

$ git rebase -i HEAD~3      # 'reword' on the middle line, new message typed in the editor
[detached HEAD f404245] Fix typo in header
 Date: Wed Nov 18 09:59:00 2026 +0000
 1 file changed, 1 insertion(+)
 create mode 100644 header.html
Successfully rebased and updated refs/heads/main.
$ git log --oneline -3
b21b6ab Add checkout
f404245 Fix typo in header
35e340f Add cart

Every commit after the reworded one gets a new hash too (compare “Add checkout” before and after), so the same push rules apply: git push --force-with-lease if it was already pushed.

To change several messages, mark several lines reword. To reach the very first commit in the repo, use git rebase -i --root.

Common slip-ups

  • Amending the wrong commit. --amend always changes the commit you’re on. If you’ve made another commit since, you need the rebase method.
  • Stuck in Vim. If the editor that opens is Vim, press i to type, then Esc and :wq to save and quit. To use VS Code instead: git config --global core.editor "code --wait".
  • Rebase stopped halfway. If something goes wrong mid-rebase, git rebase --abort puts everything back exactly as it was.

FAQ

How do I change the last commit message in Git?

Run git commit --amend -m "New message". Without -m, Git opens your editor so you can edit the existing message.

How do I change a commit message after pushing?

Amend the commit (or reword it with interactive rebase), then run git push --force-with-lease. Avoid this on branches other people have already pulled.

How do I change an older commit message?

Run git rebase -i HEAD~N where N reaches back to that commit, change pick to reword on its line, then edit the message when Git asks.

Can I edit a commit message on GitHub’s website?

No. GitHub doesn’t let you edit commit messages in the browser. You have to change it locally and force push.

Written by Admin

Writes practical Git guides for Git Commands. Every command is checked against the official Git documentation.

About Git Commands