This is the forth and last video in the Git Animated series. If you are interested in the other ones, check the links below:

Another way of integrating changes of a branch into another one is by performing a rebase. Instead of creating a new merge commit, as it happens when we merge two histories, a rebase will change the base of a branch from one commit to another. Changing the base of a branch means changing the commit that branch was created from to be some other commit.

In the animation we change the original base of feature, the commit M2, to be M3. Performing this action has the effect of integrating the changes introduced by M3 into the feature branch, together with whatever the feature branch already had on it. As you may observe, this action does not produce a new commit containing the changes of both the master and feature branches, rather it creates three new commits, F'0, F'1, F'2, which content-wise are identical to the commits F0, F1, F2, and sticks them after the commit M3. This way, the feature branch contains the changes introduced by the commit M3 too.

Observe that the master branch is still behind and knows nothing of the new commits. To bring master up-to-date too, one needs to perform a fast-forward merge of the feature into master, which in this case just means to move the master pointer to point to the last F'2 commit.

Note also, that the original commits of feature branch (F0, F1, F2), if not “revived”, will be eventually garbage-collected.

Hopefully this animation conveys some intuition on what happens when we rebase a branch onto another.

For your convenience, here are the Git commands which appear in the video:

git commit -m 'M0'
git commit -m 'M1'
git commit -m 'M2'
git branch feature
git checkout feature
git commit -m 'F0'
git commit -m 'F1'
git commit -m 'F2'
git checkout master
git commit -m 'M3'
git checkout feature
git rebase master

Here is the video(there is no audio):

Feel free to drop me a comment or e-mail with your constructive criticism. It will be much appreciated!

Enjoy!