skip to content
Alvin Lucillo

Push amended commit with new file

/ 1 min read

After you perform a commit and pushed it to the remote repository, and amended local commit to add a forgotten file (see command below), you can’t just perform git push.

git add path/to/forgotten-file
git commit --amend --no-edit

This is because both the latest commit in local and remote branches appear as sibling commits as direct descendant of the same commit. With that, use --force-with-lease to force the remote branch to use the local history safely, meaning only if the remote branch is still what git expects it to be. For example, there might be unexpected commits following the latest commit. In that case, you don’t want to just use --force since that will overwrite the remote branch, losing those commits.

git push --force-with-lease