Search code examples
gitgithubpushgit-amend

How to change a commit content after the commit has been pushed to the remote branch?


I need to change a file that i have already pushed but i don't want to do a new commit, so i tried amend. But when I try to push the changes to the remote branch it gives me an error. Do I need to do a force push or something else ?? I'm the only one working on this project so no one is going to pull this branch(I can use amend).

Thanks.


Solution

  • Yes, you can use force push, but please note that it should be allowed in your branch configuration.

    git push origin [branch] -f
    

    This will basically override the branch. So use it for shared remote branches like master with caution.