I am a beginner in Version Control and I am using SourceTree
I'm going to merge my changes from feature branch to dev branch.
Since I've made lots of changes in feature branch and I am quite sure there would be conflicts.
I am thinking 2 ways.
1. merge feature branch to dev branch directly and resolve the conflict and then commit
2. merge dev branch to feature branch first. After I resolve the conflict in feature branch,
I merge it to dev branch so that there should be no conflicts.
Which one should I use? What is the pros and cons for these 2 ways?
Rebase your feature branch on top of dev.
Rather than trying to resolve all the commits at once with a merge, rebasing will merge your individual commits on top of dev one at a time allowing you to deal with the conflicts in small isolated pieces. As you resolve conflicts in each commit you can run your tests to ensure everything still works before moving on to the next commit.
In general, rebase to update your branches.
Since I've made lots of changes in feature branch and I am quite sure there would be conflicts.
This is the root of the problem: letting the feature branch drift too far away from its upstream branch. Feature branches should be updated frequently to avoid too much drift, and merged as soon as possible. This means keeping the scope of feature branches small.
Rather than trying to tackle the whole branch, you can break it up into smaller feature branches. Identify changes which can be isolated and committed as their own branch. Use cherry-pick
to move them to a new branch, remove them from your monster branch with git rebase -i
, test and merge them individually. Continue until your feature branch is manageable.
Your branches will be easier to review and manage, and by doing each change as its own branch the changes will be better considered.
For example, if as part of your feature you do a refactoring, extract that refactoring into a new branch. Or if you wrote a new component, do that in its own branch. Or you found a tangentially related bug and fixed it, do that in its own branch.