Performing a rebase operation

When you have a long-running branch, you want to sync up with master sometimes. You can do this by merging master back into your branch, but Git has a better way of doing this. It's called rebasing. With rebasing, you can replay the commits from the branch over which you want to merge your changes. All this happens without a new commit being created and helps keep your history clean.

How to do it…

To see rebasing in action, we need to have a new branch with some commits and one commit in the master branch. Let's do that first:

  1. Go to the super-git project in your terminal and create a new branch:
    $ git checkout -b rebase-branch
    
  2. Create a new file and commit it:
    $ echo "File content" >> another_file.md
    $ git add .
    $ git ...

Get GitLab Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.