3 ms·
A somewhat lesser known git trick that's pretty much a strict improvement - use `--force-with-lease` for force pushing instead of `--force`. What this does is
by ThrustVectoring 10y ago
A somewhat lesser known git trick that's pretty much a strict improvement - use `--force-with-lease` for force pushing instead of `--force`.
What this does is check what's on the remote branch and compare it with what you think is on the remote branch, and only do the force if they're the same thing. So if someone pushes a commit, the force push errors out instead of silently overwriting it.
Basically every single time you want to force push, you probably should be doing a `--force-with-lease` instead. I can't think of a situation where you'd want to silently lose commits you don't know about rather than get an error.
- bdhess 10y agoI also can't think of a situation where you'd want to force push to a branch that others might be committing to.
- ThrustVectoring 10y agoIf they're not committing to it, --force-with-lease is the same thing as --force, so it doesn't cost you anything.
- bdhess 10y agoCosts ten keystrokes by my count. But it's not the keystrokes that trouble me, it's the idea that one of my co-collaborators might use this feature to "safely" rewrite history in a branch I'm also using. "Safely" being relative, since the rest of the collaborators will have to force pull that branch later, and rebase their pending changes. By my reckoning, rewriting history just isn't a reasonable decision in shared branches.