Check Out Bugfix Again and Rebase Onto Master
Git team workflows: merge or rebase?
Nicola Paolucci
Back to list
The question is simple: In a software team using git
and feature branching, what's the all-time manner to incorporate finished work back to your primary line of evolution? It's ane of those recurring debates where both sides take stiff opinions, and mindful conversation can sometimes be hard (for other examples of heated debate see: The Internet).
Should you adopt a rebase policy where the repository history is kept flat and clean? Or a merge policy, which gives you traceability at the expense of readability and clarity (going and then far as forbidding fast-forrad merges)?
A fence exists
The topic is a fleck controversial; possibly not equally much as classic holy wars between vim and Emacs, or between Linux and BSD, but the 2 camps are vocal.
My empirical pulse on all-things-git
– scientific, I know! – is that the always merge arroyo has a slightly bigger listen share. But the e'er rebase field is besides pretty vocal online. For examples come across:
- A rebase-based workflow
- A Rebase Workflow for Git
- A Uncomplicated Git Rebase Workflow, Explained
- A Git Workflow for Active Teams
To be honest, the divide in two camps – always rebase vs. always merge – can exist confusing, considering rebase as local cleanup is a unlike matter than rebase every bit team policy.
Aside: Rebase equally cleanup is awesome in the coding lifecycle
Rebase as team policy is a different thing than rebase as cleanup. Rebase as cleanup is a good for you office of the coding lifecycle of the git
practitioner. Let me detail some instance scenarios that show when rebasing is reasonable and effective (and when it's not):
- You're developing locally. You have non shared your work with anyone else. At this point, y'all should prefer rebasing over merging to go on history tidy. If y'all've got your personal fork of the repository and that is not shared with other developers, you're condom to rebase fifty-fifty later you've pushed to your fork.
- Your code is gear up for review. You lot create a pull request, others are reviewing your work and are potentially fetching it into their fork for local review. At this betoken you should not rebase your work. You should create 'rework' commits and update your feature branch. This helps with traceability in the pull asking, and prevents the adventitious history breakage.
- Review is done and ready to be integrated into the target branch. Congratulations! You're well-nigh to delete your feature branch. Given that other developers won't be fetch-merging in these changes from this betoken on, this is your gamble to sanitize history. At this indicate you can rewrite history and fold the original commits and those pesky 'pr rework' and 'merge' commits into a small set of focussed commits. Creating an explicit merge for these commits is optional, but has value. It records when the feature graduated to principal.
With this bated clear we can now talk nearly policies. I'll try to keep a balanced view on the statement, and will mention how the trouble is dealt with inside Atlassian.
Rebase team policy: definition, pros, and cons
It'south obviously hard to generalize since every team is different, but we take to start from somewhere. Consider this policy equally a possible case: When a feature co-operative's development is consummate, rebase/squash all the work down to the minimum number of meaningful commits and avert creating a merge commit – either making sure the changes fast-forrad (or only cherry-pick
those commits into the target branch).
While the work is still in progress and a characteristic branch needs to exist brought up to date with the upstream target co-operative, use rebase
– equally opposed to pull
or merge
– non to pollute the history with spurious merges.
Pros:
- Code history remains flat and readable. Make clean, clear commit messages are every bit much part of the documentation of your code base of operations as code comments, comments on your issue tracker etc. For this reason, it'due south important non to pollute history with 31 unmarried-line commits that partially cancel each other out for a single feature or bug ready. Going back through history to figure out when a bug or feature was introduced, and why it was done, is going to be tough in a situation similar this.
- Manipulating a single commit is piece of cake (e.m. reverting them).
Cons:
- Squashing the characteristic down to a handful of commits tin can hide context, unless you proceed around the historical branch with the entire development history.
- Rebasing doesn't play well with pull requests, considering yous tin't encounter what pocket-sized changes someone made if they rebased (incidentally, the consensus inside the Bitbucket development squad is to never rebase during a pull request).
- Rebasing tin can be unsafe! Rewriting history of shared branches is decumbent to squad piece of work breakage. This tin can be mitigated by doing the rebase/squash on a re-create of the characteristic branch, simply rebase carries the implication that competence and carefulness must exist employed.
- It's more than work: Using rebase to keep your feature branch updated requires that y'all resolve similar conflicts again and again. Yes, you can reuse recorded resolutions (rerere) sometimes, only
merges
win here: Just solve the conflicts one time, and you're set. - Another side effect of rebasing with remote branches is that yous need to strength push at some signal. The biggest problem we've seen at Atlassian is that people forcefulness push button – which is fine – but oasis't set
git push.default
. This results in updates to all branches having the same name, both locally and remotely, and that is dreadful to deal with.
NOTE: When history is rewritten in a shared branch touched past multiple developers breakage happens.
Merge team policy: definitions, pros, and cons
Always Merge-based policies instead flow like this: When a feature co-operative is complete merge it to your target co-operative (main
or develop
or next
).
Make sure the merge is explicit with --no-ff
, which forces git
to record a merge commit in all cases, even if the changes could exist replayed automatically on elevation of the target branch.
Pros:
- Traceability: This helps keeping information about the historical existence of a feature co-operative and groups together all commits role of the characteristic.
Cons:
- History tin can become intensely polluted by lots of merge commits, and visual charts of your repository tin have rainbow branch lines that don't add too much information, if not outright obfuscate what's happening. (At present to be fair, confusion is hands solved by knowing how to navigate your history; The trick hither is to utilise, for example,
git log --first-parent
to make sense of what happened.)
- Debugging using
git bisect
tin become much harder due to the merge commits.
Decisions, decisions, decisions: What practise yous value almost?
And then what'southward best? What exercise the experts recommend?
If you and your squad are not familiar with, or don't sympathise the intricacies of rebase
, then yous probably shouldn't use it. In this context, always merge is the safest option.
If you lot and your team are familiar with both options, then the main decision revolves around this: Practice you value more a clean, linear history? Or the traceability of your branches? In the start case go for a rebase policy, in the later go for a merge one.
Note that a rebase policy comes with small contraindications and takes more effort.
At Atlassian
The policy inside Atlassian'south Bitbucket squad is always to merge feature branches, and require that branches are merged through a pull asking for quality and code review. Simply the team is not also strict around fast-forward.
Conclusions and acknowledgements
This article is the result of the confluence of insightful exchanges (pun intended!) with the Bitbucket team on the topic.
This piece hopefully dispels the doubts on this, and allows you to adopt an approach that works for your squad. Follow me @durdn, and the fantastic @AtlDevtools team for more git
awesomeness.
Source: https://www.atlassian.com/git/articles/git-team-workflows-merge-or-rebase
0 Response to "Check Out Bugfix Again and Rebase Onto Master"
Post a Comment