Fork me on GitHub
Learn more at the sources:

Git Rebasing

This Guide will elaborate on teamwork in git and using branches.

After reading this guide, you will know:

  • Hot to rebase

1 What is a commit, what is a branch.

Every commit is just a small change that points to the commit before.

A branch is just a pointer to a certain commit.

If you create a branch called a3 and add a few commits W, X, Y, and Z to it, it might look like this:

If you merge back into master now everything will be fine.

But what if the master moves on?
Let's say three other commits are added to the master: B, C and D:

If you merge this, the merge might get complicated. A new Commit is created that contains all the necessary changes:

But there's a better approach: First you rebase your branch onto the master:

git checkout a4
git rebase master

This will try to apply the new commits in a4 on top of the current state of master, leading to this situation:

After the rebase a merge into master will be simple.

1.1 Resources