I am working on a project with quite few others (OSS) and constantly hitting merge conflicts, which I then turn into a dumpster fire. Sometimes things go well, other times I just close the PR. Make a fresh branch and start again, as git and GitHub have fallen out.<p>My current approach is:<p>1. Change to main<p>2. `git pull` latest changes<p>3. Change to my feature branch<p>4. git merge origin/main<p>5. Get CONFLICTS<p>6. Fix CONFLICTS<p>7. git add -A<p>8. git commit -m "Rebase from main"<p>9. Fingers crossed, git push origin myfeature<p>I have also tried `git rebase origin/main` at #4, but this often pulls everyone elses commits into my change, which gets me complaints during review.<p>At this point it will either go well, or blow up. Sometimes GitHub will claim there is still a merge conflict, even though my local file and the remove file in main are identical. Other times I have new commits locally, I push them upstream and git tells me<p>Is there any idiot proof approach I can take here. I am guessing this is more the tradesmen at fault, more than the tools. So willing to look a fool here, but this is a bit of a PIA right now.
If merge conflicts are that common, either you're all tripping over each other trying to do things in different ways, or they are "artificial" conflicts caused by people rebasing public shared / branches.<p>Merge conflicts should be occasional, not an everyday occurrence.<p>Atlassian's golden rule: Never rebase a public branch.<p>Try to understand where conflicts are coming from. Are people committing different linting/whitespace/line-endings.<p>If so, then get automated tooling on the repo which enforces a linting and style guide to prevent re-format conflicts.<p>If they're from genuine refactors, try to understand why people are refactoring so much in a way that is causing conflicts.