Ubuntu - GIT - git rebase

Copies commits/branch to another commit/branch directly.

All the changes that were committed on a branch are replayed on another. This creates a nice linear sequence of commits as the two parallel (merge combines two endpoints) commits seem like they were done sequentially. This especially helps when you're contributing to project (all they'll have to do is a fast-forward). The caveat is that all commits on the way to the rebase target are applied, even if they were just used for debugging purposes, etc.

If you use the interactive version (-i), you could pick and reorder the commits you want. This is great if you don't quite know which commits you want to apply and would like to see some metadata on them.

git rebase -i HEAD~3 –aboveAll

Rebase also allows you to edit previous commit messages (reword), combine multiple commits (squash), split commits (edit), and delete/revert commits.

Don't rebase commits that have been pushed publicly as others may have already based work on those commits. If it's necessary makes sure git pull –rebase is used.

If you want to replay changes from a topic branch that's branched off another topic branch you could use

git rebase –onto master topic1 topic 2 

which will replay only the changes to topic2 not common to topic1 to master.


GIT Revase vs. Merge

Merge will give you a record of exactly what happened during the entire history.

Rebase will clean up that story so that it's easier for developers to see how the project was created.

Rebase locally to clean up the story before you push.

Never rebase after you've pushed.