Most of the teams I've worked on in the past have followed the same workflow when using Git (with some tiny variations):
- Pull the
developbranch (git checkout develop) - Create a new feature branch off of it (
git checkout -b feature/XYZ-123) - Do your work
- When you are ready to create a PR, add and commit your changes (
git add . && git commit -m "some commit message"), then checkdevelopback out, pull it (git checkout develop && git pull) - Switch back over to your feature branch and merge
developinto it (git checkout feature/XYZ-123 && git merge develop) - Finally push (
git push -u origin feature/XYZ-123) and create a PR
We'll call this the "Merge Method". The benefits are that any changes to develop since you created the branch are now merged into your branch. And so by the time you create a PR, there are no merge conflicts with develop and the code reviewers can see a clean, conflict-free diff between your branch and develop.
I am now working on a team that has a similar flow up until the merge step, but then instead of merging develop into my feature branch, they ask for a rebase from origin/develop. So the actual steps are:
git checkout developgit checkout -b feature/XYZ-123- Do your work
git add . && git commit -m "some commit message"git checkout develop && git pullgit checkout feature/XYZ-123- Rebase from
origin/dev git push -u origin feature/XYZ-123
We'll call this the "Rebase Method". It too produces merge conflict-free PRs, but obviously it must have different pros/cons from the Merge Method explained up above.
I'm wondering what those pros/cons are. What does the Merge Method lend itself to that the Rebase Method lacks, and vice versa? When should one method be used as opposed to the other?