6/1/2026 at 1:36:19 PM
I never get conflicts during a merge because I only ever merge in one direction. I get all my conflicts on branches because I rebase before merging. I started doing this years and years ago because I kept coming across these mysterious silent regressions with my team. I searched something like "git merge silent regressions" and came across this stackoverflow answer:https://stackoverflow.com/a/28510260
That completely fixed the problem. Now I only ever get conflicts on my feature branches. The rule is always: rebase away from main, and merge towards main. All conflicts are then on your branches, never on main, and always from rebase, never from merge. Then I set the pull behaviour to rebase, too.
I've never had a silent regression since, and never had a problematic conflict scenario.
I did recently learn about ORIG_HEAD though which was very cool, because I had accidentally rebased to main instead of to a dev branch from which I had created a bunch of worktrees, then when I merged back to the dev branch all hell broke loose, and I learned that I could revert a merge by checking out ORIG_HEAD:
by dools
6/1/2026 at 3:39:12 PM
I'm also like this, rebasing feature branches onto main - I however have one suggestion when it comes to the push back up to originInstead of
`git push --force`
always use
`git push --force-with-lease`
https://git-scm.com/docs/git-push
This probably should be the default in git (as in there should be a `git push --force-without-lease` instead) and asks git to make sure the commits locally on your branch are up-to-date with those on remote/origin. It then fails if you try to overwrite commits that you haven't seen, and has saved me a few times when working between computers on the same project when i could have lost history on the remote that i failed to fetch.
by acallaghan
6/1/2026 at 5:03:37 PM
--force-with-lease serves no purpose.If you are sure that the repo you are pushing to is a stable target (nobody else is accessing it), you just use --force.
If the repo you are pushing to is a moving target, you ... don't force push to it. Or else you warn all the repo users that you are about to rewrite history. Which means they not only should refrain from pushing, but have to be prepared for a second announcement which informs them that the rewrite is done; they must then fetch the rewritten head and fix up their unpublished work against the non-fast-forward change.
Now it may be that --force-with-lease allows you to sneak in non-fast-forward changes without losing newly introduced upstream changes: but that assumes it's a good idea to be doing that sort of thing without communicating with your team. I.e. as long as we can sneak in a non-fast-forward change without accidentally/unknowingly deleting anyone's work, we are peachy; no need to coordinate.
by kazinator
6/1/2026 at 11:01:22 PM
>If you are sure--force-with-lease exists for the scenario where you are sure, but wrong.
by nlawalker
6/2/2026 at 12:03:24 AM
I don't see how you could be wrong in knowing whether you're the only user with push access to the remote repo, or there are others.by kazinator
6/2/2026 at 1:28:48 AM
You could have multiple computers, checkouts, or worktrees pointing at the same branchby bathtub365
6/1/2026 at 8:47:04 PM
I wouldn’t say it serves no purpose. It is useful when rewrites are tolerable and loss of history is not. It’s the default when using tools like jj, because the expected workflow wraps git in a way that force pushes are frequent and expected, but blowing away someone else’s work by mistake is not.by twodave
6/1/2026 at 5:21:18 PM
I follow this approach and still get the same merge conflicts coming repeatedly while doing rebase.Let's say in my feature branch in the first commit I change a line in a file which also gets changed in the main branch. Then I have done 3-4 change commits doing changes in the same file. Now while doing rebase, I will have to resolve this conflict 3–4 times again and again while git re-applies commit one by one, during rebase.
I think I get this sometimes even if rerere is enabled, I am doing rebase using Intellij though, so maybe rerere doesn't get used here somehow or maybe diff context changes, so rerere is not applicable.
by overtomanu
6/1/2026 at 5:39:15 PM
We usually squash feature branches before merge. To squash before rebase, I use git reset --soft $(git merge-base develop HEAD) && git commit && git rebase develop - you have to resolve final conflicts onlyby alexsmirnov
6/1/2026 at 3:43:48 PM
If you squash merge PRs, this is equivalent to merging master back into your feature branch before merging to master.I do that a lot to avoid commits mutating mid-review, so you avoid having to force push over reviewed commits (which is a sin)
by lelandfe
6/2/2026 at 12:59:02 AM
Squash merging PRs makes your commit log is far less useful.The PR reviewer isn't the only person who will ever review your code, you know.
by dolni
6/1/2026 at 6:11:02 PM
That’s a funny Stackoverflow answer. That explanation cannot cause code loss. At least not with plain Git.What I would check is hooks, or any other customizations. Especially on Windows, data loss is absolutely possible with misconfigured hooks, but it has nothing to do with when a commit was made.
by ruszki
6/1/2026 at 2:48:14 PM
rerere is still useful here to handle merge conflicts after repeated rebases.by barbazoo
6/1/2026 at 3:38:22 PM
As someone who tried rerere and didn't see the point:How? Usually I rebase the same branch multiple times onto different, but successive commits of the master branch. But after I solved a bunch of conflicts of the first rebase, I shouldn't have the same conflicts again in a second one, since the rebased branch contains the merged conflict. Rebasing again could only turn up new conflicts (with newer, other commits on the master branch).
How can I have the same conflict again for repeated rebases?
by mqus
6/1/2026 at 5:06:56 PM
The point is that some organizations have a chaotic development process consisting of numerous similar branches. Often there is a main trunk, and then branches that were made for particular product variants (like piece of hardware or whatever) and cut at a particular point in time, in order to isolate from the trunk.What then happens is that when a bug is found that affects all branches, it must be cherry picked into all of them. If that cherry pick runs into conflicts, it is often the same conflicts, over and over again on each branch.
Of course, the fix is not to do that, but it's easier to say that than to get away from that kind of workflow once you are steeped in it up to the chin.
by kazinator
6/1/2026 at 7:01:37 PM
> Often there is a main trunk, and then branches that were made for particular product variants (like piece of hardware or whatever)I worked at a place that did this.
The code was written in C, and I always thought the better solution would have been to use #define/#ifdef to flag certain blocks of code out of the compilation.
A branch for each product was a nightmare when there were 10+ products, some with multiple variations, each on its own branch. Backporting a bug fix meant cherry-picking into 20+ branches. What made it especially stupid was office politics from each product having its own PM, and then the PM for one of the products would decide the bug wasn't significant enough to spend the time doing the cherry-pick and testing. This happened too often when it came to security fixes when a PM didn't understand the issue.
by Sohcahtoa82
6/1/2026 at 9:01:52 PM
Yes; #ifdef and #endif is basically branching, but it's in one branch of the CM system.The benefit that everything is integrated, so there are no games with having to cherry pick things this way and that and losing fixes.
The apparent downside is that there is no isolation. Inside some of those #ifdefs is code that you are not building. But changes you are making can break that code for someone else.
While this may seem risky, it's actually better. Breaking something now is better than someone cherry picking your fix 8 months later into their branch and then dealing with the breakage.
Fixes to common code never get left behind; everyone working off the trunk instantly gets them.
The #ifdefs are immediately and constantly visible, telling you where the code is that is or is not part of what you are doing, and reminding you of its existence. They greatly discourage refactoring parts that you cannot test.
There is pressure to keep those #ifdefs clean, whereas people go hog wild when they have their own branch, thinking they can rewrite whatever they want to suit what they are doing.
by kazinator
6/1/2026 at 8:04:54 PM
Happens all the time with long term dev branches, which tend to arise when the PR review process is such a bottleneck that work piles up. Anything cherry-picked out of those branches tends to run into similar conflicts. ReRe is pretty handy in those circumstances.by chuckadams
6/1/2026 at 3:54:31 PM
I know what you mean but doesn't that require squashing as well? If I have a branch with 5 commits, I think rerere helps me by only having to fix the conflict once, not potentially multiple times. I might be wrong here though.by barbazoo
6/1/2026 at 3:36:30 PM
This is what I've been doing for years. It's remarkably stress-free!by techwizrd
6/1/2026 at 1:43:03 PM
I've never even seen someone suggest a rebase master onto feature workflow! TIL.by ubercore
6/1/2026 at 1:46:21 PM
I think the terminology would be the other way around, like you're rebasing the feature onto the main:git checkout feature
git rebase main
git checkout main
git merge feature
that way you get all your conflicts on the feature branch during rebase and your merge is always clean.
by dools
6/1/2026 at 2:49:52 PM
> I get all my conflicts on branches because I rebase before mergingPretty sure it's the other way around. You're on the branch and rebase it atop current master. If you merge after that, you won't have merge conflicts.
by barbazoo