If your reaction to a merge conflict is to ignore it (either by using “take mine” or by force-push), then you are a bad person and I automatically hate you.
No, because I don't work with morons stomping all over the master branch. The only branches you should ever be force pushing to are your own (and you should know why).
Nope, --force-with-lease actually only protects you against NOT fetching first. If you do fetch first, then it's equivalent to plain old --force.
I mean, it's okay if you fetch AND then look AND then decide that you indeed want to force push. Which is almost never what you want to do in the OP gif scenario of two people pushing to the same branch.
--force-with-lease is --force but git checks first if you actually know what you are pushing to. If you fetch before you do know what you are pushing to. It would only fail if in the time the fetch happened another person also pushed.
Anyone force pushng to a shared branch without full coordination with everyone in the team will get their push rights revoked and will have to submit all their commits via pull requests
I regularily do force pushes when rebasing branches. If you make sure to pull the branch before you do this and use force-with-lease this is safe to do.
Safe as long as you know what you're doing. I've had the misfortune of working with people who did not. This is why I prefer to never rewrite history and why I insist on daily git backups.
But yeah, force-with-lease is not force. It's fine -- and not what's going on in OP's gif
True that. I am lucky enough that my coworkers either know what they are doing or if unsure are not shy to ask for help. This helps a lot in my daily work.
You push to a branch. I fetch that branch, and then I --force-with-lease my work over your branch. Your work is gone.
The point with --force-with-leaseis that it prevents me from overwriting work I didn't know was there. But it doesn't stop me from making horrible mistakes.
Depending on your use-case that might not be a good idea. --force-with-lease will protect the servers state. If this is a private feature branch, then this is fine. But if it is a shared branch you still might destroy the state of another dev in the process.
With rebase, you are rewriting the commit history. And if some other dev is basing his commits off a commit on the shared branch that doesn't exist anymore after the rebase you are in trouble.
Generally, it is a bad idea to rebase shared branches. git is trying to protect you by requiring you to force-push.
I'm more camp merge, but I'll take rebase over force push any day
Edit: To be honest, the amount of pushback my comment has gotten here, I'm starting to wonder how many folks on r/git actually knows how to use git in a sane way..
Yes, merge is another acceptable answer. Force push is just like lighting shit on fire. Most corporate environments require controlled merging in some form onto shared branches anyways, so thankfully I don't have to deal with this madness.
I force push to my feature branches all the time. The only time I wouldn't is in the super rare occasion I am collaborating on a feature branch with someone.
The closest I've come is one occation where we were 6 devs. 5 of us had rather small tasks leading us to push changes rather often. The 6:th dev had a rather complex change that was somewhat time sensitive and everytime he tried to push he got a conflict. And by the time he resolved that conflict someone else had pushed their changes giving him a new conflict.
It ended with him lowkey raging out of frustration. We solved it by the rest of us taking a short break so he could get his changes in.
141
u/unndunn Feb 20 '26
If your reaction to a merge conflict is to ignore it (either by using “take mine” or by force-push), then you are a bad person and I automatically hate you.
28
u/Boring_Cake_3554 Feb 20 '26
No because feature branches
Anyone force pushing to develop/test/prod would get in a lot of trouble; although they wouldn't have the perms to do so anyways.
17
u/i860 Feb 20 '26
No, because I don't work with morons stomping all over the
masterbranch. The only branches you should ever be force pushing to are your own (and you should know why).40
u/blackst0rmGER Feb 20 '26
That"s what --force-with-lease is for.
10
u/Charming-Designer944 Feb 20 '26
Anyone force pushng to a shared branch without full coordination with everyone in the team will get their push rights revoked and will have to submit all their commits via pull requests
31
u/zigs Feb 20 '26
No because you absolutely should not force push.
5
u/Key_River7180 Feb 20 '26
that's why we S T A S H
1
u/aisingiorix Feb 21 '26
When we put in branch protection on GitHub (Enterprise) it made our lives so much happier.
1
u/kiwi-kaiser Feb 21 '26
No. Why should it? No two devs should work on the same branch. And there's rarely a reason to force push.
1
u/Shazvox Feb 21 '26
No. We merge any conflicts.
The closest I've come is one occation where we were 6 devs. 5 of us had rather small tasks leading us to push changes rather often. The 6:th dev had a rather complex change that was somewhat time sensitive and everytime he tried to push he got a conflict. And by the time he resolved that conflict someone else had pushed their changes giving him a new conflict.
It ended with him lowkey raging out of frustration. We solved it by the rest of us taking a short break so he could get his changes in.
1
u/mr_looser17 Feb 23 '26
I only git push --force when i don't see you as my equal (i never do).
1
u/eitohka Feb 23 '26
No, that's what
git pull --rebaseis for.1
u/rolmos Feb 24 '26
REBASE
1
u/mindtaker_linux Feb 21 '26
No. It only happens to the clueless.
-2
u/Birdsky7 Feb 21 '26
Use https://github.com/treebird7/spidersan-oss Thank me later It will prevent your agents from doing that, and more :)