Overview
Teaching: 20 min
Exercises: 0 minQuestionsObjectives
- What is the advantage of merging?
- What is the advantage of rebasing?
- Why is the Git log history important?
- Obtain a mental representation of the rebase model.
- Learn how to name branches.
To illustrate rebasing we consider the following situation - we wish to merge
master into devel:
Now you know how to do it:
$ git checkout devel
$ git merge master
This creates a merge commit:
But there is an alternative for integrating master commits into the devel
branch:
$ git checkout devel
$ git rebase master
git rebase replays the branch commits b1 to b3 on top of master.c5.b1 to b3 have been replaced by b1* to b3*).git rebase makes “merges” producing a linear history.git merge resolves all conflicts in a single commit, with git rebase each commit may need
conflict resolution.git rebase may invalidate tests.git merge preserves chronology of commits and creates explicit merge commits (unless fast-forward).git rebase can change chronology of commits.

joe/new-integrator).$ git branch -r | grep joe
issue-137).For release branches we recommend e.g. release/2.x or stable-2.x.
feature-a, feature-b, feature-c.stockholm, san-francisco, helsinki.stockholm, san-francisco, and helsinki will either diverge
(three main development lines) or somebody will spend a heroic effort to keep
them synchronized.git bisect it is very helpful if all commits build/compile.Often we have this situation (newest commit is on top):
$ git log --oneline
6e129cf documentation for feature C
05344f6 small fix for feature C
bc11c47 save work on feature C
aa25177 feature B
6b58ba4 feature A
But we would prefer to have this history:
$ git log --oneline
81e100c feature C
aa25177 feature B
6b58ba4 feature A
git reset --soft aa25177.aa25177
but we keep the working tree of the last committed state.git reset --soft is an interactive rebase.git cherry-pick).Key Points
Rebasing creates nice linear history without merge commits, but is associated with potential risks.
Having one main development branch which is documented, tested and has logical commit history is useful to both developers and users.