How to Change Last Git Commit Message After Pushing?

Find out how you can change git commit message of the most reason commit

To change the recently pushed git commit message, you would need to do the following:

# 1. checkout the branch on your local
git checkout <branch-name>

# 2. amend the commit message
git commit --amend -m "New message"

# 3. force-push to update remote repository
git push --force-with-lease <remote-name> <branch-name>

In the third step, you could also use the --force flag instead of --force-with-lease. However, when you're working in teams, it is generally a safer option to use --force-with-lease as it will abort if there are any upstream changes to the same branch after your last commit. In contrast to this, --force would destroy any pushed changes (after your last commit) to the same branch.


Hope you found this post useful. It was published . Please show your love and support by sharing this post.