Reputation: 531
I have a github repository which follows the following branching strategy :-
Now, assuming feature/A and feature/B are being worked upon simultaneously and the team working on feature/A finishes the feature first and raises a simple Pull Request to merge changes to master branch.
After the work on feature/B is finished, we would like to rebase it on top of master to get the latest changes from master (which contains feature/A work) before raising a pull request to merge changes from feature/B branch to master.
What is the proper way to do rebase in this case?
Here are 2 approaches I have tried out -
Approach 1 :-
Questions on this approach 1 -
Approach 2 :-
Questions on this approach 2 -
Upvotes: 5
Views: 3987
Reputation: 114219
Git allows you to rewrite history (rebase) and force that onto the remote (assuming the required permissions) with git push -f
.
The other way to combine divergent history is to merge. For example, you could first merge master into feature/B to resolve conflicts instead of doing a rebase. Or you could merge directly into master.
If you have multiple people working on feature/B, rebasing is generally not the best approach, unless all work has stopped and everyone is ready to close the branch. Otherwise, it can create race conditions where someone pushes changes after you start the rebase, but before you force-push, losing their work.
If you insist on rebasing, Approach 1 will give you no avantage. Approach 2 is almost the correct way to do it. The only problem is step 4 is undoing all the benefit of the rebase. Instead of merging feature/B with origin/feature/B, you need to do git push --force
to update the remote with the new commit history.
As Approach 2, step 4 implies, merging may still be the best approach in your situation.
Upvotes: 2