Book Image

Git Best Practices Guide

By : PIDOUX Eric
Book Image

Git Best Practices Guide

By: PIDOUX Eric

Overview of this book

Table of Contents (12 chapters)

Rebase


As we just saw, the merge command combines the changes from two branches. The rebase command will take the changes from the first branch and apply them to the other branch.

In the rebase command do not merge commit!

The following diagram displays the current state of our repository. We have the master branch pointed on Commit 3 and a branch pointed to Commit 4:

Our goal is to rebase branch from master, so we need to checkout on master and rebase it:

Erik@local:~/webproject$ git checkout branch
Erik@local:~/webproject$ git rebase master

The rebase command can be used if you want to get a feature (commits) from one branch to another and be sure to be close to the tip of the upstream branch. As we just saw, the command applies the changes from the branch called branch to the master branch.

In this schema, commit 4 is applied on master by using the name commit4bis, and the original commit 4 is deleted by the garbage collector.

The --interactive option will stop after each commit to change...