Best Practices
Safe force-push protocol
When history rewrite is necessary, use explicit communication, freeze windows, and `--force-with-lease` to reduce overwrite risk.
- Individuals or teams who want more predictable Git habits
- Maintainers setting collaboration expectations
- At least one real collaboration loop
- Basic command familiarity without a stable routine yet
- Treating guidance as absolute law without context
- Memorizing process without understanding team boundaries
Citations & Further Reading
- Git push [Official]
- Git reflog [Official]
- Git Tools Rewriting History [Book]
What you will learn
- Understand the core purpose of Safe force-push protocol
- Master the basic usage and common options of Safe force-push protocol
- When history rewrite is necessary, use explicit communication, freeze windows, and
--force-with-leaseto reduce overwrite risk. - Understand key concepts: Minimal protocol
- Know when to use this feature and when to avoid it
Force-push should be governed, not improvised.
Start with a problem
Your team has developed some Git habits over time, but you're not sure if they are optimal — or you've just been through an incident caused by a Git mistake and want to avoid repeating it.
Minimal protocol
- restrict allowed branches
- announce temporary push freeze
- default to
--force-with-lease - share post-push recovery guidance
Confirm no one based on current branchCreate backupUse --force-with-lease
Does not overwrite others' workRecoverableTeam can sync
--force-with-lease is the safe version of force-push; it checks whether remote matches expectations.
Recommended sequence
git fetch origin
git log --oneline --graph --decorate -20
git push --force-with-lease origin <branch>
Why lease matters
--force-with-lease prevents overwriting remote commits you have not seen.
The collaboration recovery cost is often much higher than the history-cleanliness benefit.
Good follow-up reads
Try it yourself
- Practice the safe-force-push-protocol command in a test repository and observe state changes before and after
- Experiment with different options and compare the output differences
- Simulate a real scenario where you would need to use this, and walk through the full process
Further reading
Keep going on the same topic: