Edit last commit message in Github

Edit last commit message in Github

Edit most recent commit that has not been pushed

To edit the message of the last commit in GitHub, you can use the git commit --amend command. This command allows you to make changes to the most recent commit, including the commit message. Here's how to use it:

  1. Make sure you are in the correct branch by running git branch.

  2. Run the command either:

    git commit --amend -m "New commit message" will allow you to set the commit message directly in the command line.

    or

    git commit --amend will open the text editor, where you can edit the commit message. Edit the commit message and save the file. Exit the text editor.

Make sure you don't have any changes staged before doing this or they will get committed too. (Unstaged changes will not get committed)

Commit message already pushed to remote branch

If commit has already been pushed to remote branch then you will have to force push a commit message after amending your commit locally(following the above steps)

git push remote <branch-name> --force or git push remote <branch-name> -f

Warning: force-pushing will overwrite the remote branch with the state of your local one. If there are commits on the remote branch that you don't have in your local branch, you will lose those commits.

Further reading

GitHub docs