Pushing after Rewriting History
Last updated
Last updated
If we've previously pushed the branch, the server will reject our push after rewriting history, which can be forced with --force-with-lease
.
Important:
Before using the commandline version of force push such as git push --force-with-lease
or git push --force
, you should make sure the push default
setting is not match
. When it's match
git will push all your local branches that matches the branches on the remote server thus extremely dangerous when combined with force
See https://git-scm.com/docs/git-config#git-config-pushdefault for other options
Force with lease is a little bit safer than force as it checks if the remote branch at local PC is the same as the branch at the remote server, for example, the push of awesome_branch
to GitHub (let's say we are using GitHub) will fail if the local origin/awesome_branch
at our side is different to the awesome_branch
on GitHub (Someone else may have pushed something to the branch, but we haven't fetch the commits).