Go Back
ยท1 Min Read

Amend The Last Git Commit

How to add forgotten changes to your previous Git commit.

gitgithubversion-control

Forgot to add something to your last commit? You can add the changes to the previous commit instead of creating a new one.

Commands

git add .
git commit --amend --no-edit
git push --force-with-lease

What Each Command Does

  • git add . - stages all your changes.
  • git commit --amend --no-edit - adds the staged changes to your previous commit without changing its message.
  • git push --force-with-lease - pushes the amended commit to the remote repository.

Important

git commit --amend rewrites the previous commit. If you already pushed that commit, use:

git push --force-with-lease

--force-with-lease is preferred over --force because it helps prevent accidentally overwriting someone else's changes.