I have a github repository which follows the following branching strategy :-
- Has a long living master branch
- feature branches are cut off from master whenever a new feature has to be worked upon. Eg. feature/A, feature/B
- Story, defect or task branches are cut off from individual feature branches which they are part of.
- Multiple features can be in development parallely.
- Story, defect, task branches are merged to respective feature branches as and when the work for these are complete.
- After completion of each feature, the work done on that feature has to be merged to master branch
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 :-
- Create a new brach from feature/B branch on local working copy, eg. - task/rebase
- Run git rebase master
- Resolve conflicts and continue rebase iteratively until it completes.
- Push task/rebase branch to remote repository.
- Raise a PR from task/rebase to master.
Questions on this approach 1 -
- Shall the PR be raised from task/rebase to feature/B? In this case, it anyway does not allow to merge the changes.
- If following this approach, how to get the changes in feature/B branch after step 5?
Approach 2 :-
- Checkout feature/B branch on local working copy.
- Run git rebase master
- Resolve conflicts and continue rebase iteratively until it completes.
- Pull from remote feature/B branch as the local copy has diverged and does not allow a push before a pull. Resolve some conflicts again.
- Push changes to remote repository and raise PR from feature/B branch to master branch.
Questions on this approach 2 -
- Is it the proper way to do rebase? I see repeated commits when PR in step 5 is raised.