DEV Community

Discussion on: How to Prevent Merge Conflicts (or at least have less of them)

Collapse
 
goncalorodrigues profile image
Gonçalo Rodrigues

I absoultely hate merge conflitcts. As you said, they aren't completely avoidable but I'm pretty much doing what you outlined and it works for me.

My workflow is like:

Start writing code on a new branch
When done, commit my changes (always striving for small commits)
Pull and rebase changes from main (git pull origin main --rebase)
Push

If there are any changes while the the PR is under review, I just rebase again and push force. This makes my branch history clean and is fine because usually there's a single person per feature branch.

Also, and this might be controversial, I strive to have a single commit per PR. So I often do git commit --amend followed by git push -f when doing small fixes. I guess I picked this up from when I worked at Google and we don't use branches there and there's always exactly 1 commit per PR (called a changelist) and now I can't work any other way :)

Collapse
 
blackgirlbytes profile image
Rizèl Scarlett

ah, very nice! I love to hear about developer's workflows. Although the last part is a little controversial, this sounds like it works well for you. I hope your comment is helpful for other people.

I think sometimes people have to experiment and figure out what workflow is best for them as individuals and as teammates.