The git rebase command is one of the most powerful commands in Git. It has the ability to rewrite your repository’s commit history, by rearranging, modifying, and even deleting commits. Trying to understand all its capabilities might take you the rest of the book. Instead, you’ll focus on the two primary reasons for using git rebase: keeping up with the repository you’ve cloned, and cleaning up your branch before you merge it.
When you clone a repository, you have a copy of that repository. But your collaborators will often add changes to the original repository. You can use git pull to refresh your clone, but if you’ve created a local branch to isolate your development, you may need to resync your branch to incorporate the changes from the original repository. The git rebase command handles this, and if you’re collaborating on an active repository, you’ll find yourself using this technique to keep up with the upstream branch. (Remember, the upstream branch is the original source that you branched from.)
The git rebase command also allows you to clean up and edit your commits before you perform a git merge of your local branch. In this chapter, you’ll use git rebase --interactive to exercise full control over how you clean and edit the commits on your local branch.