A regular git push will be rejected because the histories don't match. The first option is
git push --force, which overwrites the remote branch with our local version.The Usual Approach:
git push --forceCode
# DANGEROUS - can overwrite other people's work
# We do it everyday though
git push --force origin <feature-branch>The Safer Alternative:
git push --force-with-leaseCode
# SAFER - includes safety checks
git push --force-with-lease origin feature-branchHow
--force-with-lease works:• Checks if the remote branch has moved since we last fetched it.
• Only overwrites if the remote is exactly where we expect it to be.
• Fails safely if someone else has pushed commits we don't have locally.
• Prevents accidental overwrites of other people's work.
PS: Might sound simple, but helps a lot when working with bigger teams.
#git #github