Reputation: 453
We have two branches in the remote git repository: master branch and develop branch. When I merge develop branch into master branch, how can I avoid merging conflict? If I solve the conflict in the master branch, then I need to merge master branch back to develop branch to keep develop updated. I do not think it is a good practice. Can anyone help me with this?
My question is more on what the best practice to merge develop branch to master branch to keep master branch clean.
Thanks
Upvotes: 5
Views: 5976
Reputation: 169
I dont think there is anything wrong with the way you suggested. There is no way to 'sync' branches. I've used this method:
(develop)$git merge master
Resolve conflicts then:
(develop)$git checkout master
(master)$git merge develop
There should not be any conflicts since you already resolved them, but if there are accept all changes from develop since they are the changes you want. (Not too clear about what happens here, would need to test again to be sure)
If you mess up do:
(either branch)$git reset --hard HEAD~1
Now your branch is right before you did the merge. If you did a rebase it would be harder to undo a mistake because it changes your git history.
Upvotes: 3
Reputation: 36710
My question is more on what the best practice to merge develop branch to master branch to keep master branch clean
You could follow gitflow, see detailed explanation here: https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow
In summary:
Upvotes: 6