Need Assistance?

support@tutorialshub.in

Advanced Git

Force pushing safely

ADVERTISEMENT
Git Free Lesson
5 min read
ADVERTISEMENT

Why force push exists

After rebasing or otherwise rewriting a branch, the remote branch may reject a normal push because its history no longer matches the remote reference. A force push asks the server to move the remote reference anyway.

Prefer --force-with-lease

--force-with-lease checks that the remote branch is still at the state you expect. This reduces the chance of overwriting someone else's newly pushed work compared with an unconditional --force.

Never rewrite protected shared branches casually

Main or production branches are often protected for exactly this reason. Use pull requests and team policies instead of rewriting shared history.

ADVERTISEMENT