Everyday that I use GIT (if you’ve been reading previous posts I’ve been using GIT for several months now, going on a year), I’m learning something new. This is something I started using fairly recently when several dev guys including myself started updating the same branch.
What I learned was that in Git, there are two main ways to integrate changes from one branch into another: the merge and the rebase.
The easiest way to integrate the branches, is the merge command. It performs a three-way merge between your forked branch, the trunk branch and an updated version of the trunk branch.
GIT Rebasing is great when multiple people are working on the same branch
However, with the rebase command, you can take all the changes that were committed on one branch and replay them on another one. Your dialog window will show the following if you ran the following command in your branch called “experiment”;
$ git checkout experiment $ git rebase master
Then this happens…
First, rewinding head to replay your work on top of it... Applying: added staged command
In short, treat rebasing as a way to clean up and work with commits before you push them, and if you only rebase commits that have never been available publicly, then you’ll be fine. If you rebase commits that have already been pushed publicly, and people may have based work on those commits, then you may be in for some frustrating trouble.