Basics of Git Rebase

Git Rebase is only one of the powerful features of git and it allows you to have a clean history in a highly branching workflow.
2013-03-30 20:18
Tugberk Ugurlu

You may wonder why the title starts with "Basics". The answer is simple: I know only the basics of git rebase :) It's only one of the powerful features of git and it allows you to have a clean history in a highly branching workflow. "Rebase" is quite powerful as mentioned and what I'm about to show you is only one of the reasons why to use rebase. I highly recommend Keith Dahlby's NDC talk which he took some time to show the rebase feature.

Let's see the easiest sample where rebase comes handy. We have the following history where we have two branches: master and feature-1.


Typically, what you would do here is to merge the feature-1 branch onto master which is fairly reasonable and it works. However, it creates you a unnecessary commit + a ridiculous graph which would be a mess if you think of hundreds of branches:


What you can do with rebase is to patch the feature-1 branch onto master. Later then, you can merge from there. The following command is what you need to run:


After running the rebase command, we can run "gitk –all" to see the graph:


It's now nice clean history. Notice that the master is still pointing where it was. It's because we haven't merge the feature-1 branch yet. Let's checkout to master branch and run "git merge feature-1" to merge feature-1 branch onto master branch:


Nicely done! Open up the gitk one more time and see the clean history:


After we remove the feature-1 branch by running "git branch –D feature-1", we won't have any trace from feature-1 branch which is absolutely OK as feature branches are just the implementation details, that's all.


Rebase can hurt

With git rebase, at the very basic level, you are messing with the history which can be dangerous depending on the case. On the other hand, when you have a collision, it's not a picnic to solve those collisions with interactive rebase without a deep firsthand knowledge but it's worth looking into even if it seems hard at the first glance Smile


Niels Holst
by Niels Holst on Thursday, Apr 04 2013 12:14:12 +03:00

Thanks a lot! I just tried your recipe and it worked. I have not yet made up my mind whether distributed source control is inherently difficult, or whether Git itself makes it difficult.

more info
by more info on Friday, Oct 21 2016 12:29:52 +00:00
Here is the place where you will get many more info about generating of paypal money generator as you will be able to generate the unlimited money in your paypal account.
by zapya on Tuesday, Oct 25 2016 12:02:44 +00:00
Download Zapya for PC to share files and folders easily from PC to other devices