Book Image

Gitlab Cookbook

By : Jeroen van Baarsen
Book Image

Gitlab Cookbook

By: Jeroen van Baarsen

Overview of this book

Table of Contents (16 chapters)
GitLab Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 commit -m 'Another commit'
    
  3. Now, switch back to the master branch:

    $ git checkout master
    
  4. Create a commit in the master branch:

    $ echo "1" >> README.md
    $ git add .
    $ git commit -m 'Commit in master'
    
  5. We also want to have the commit that we...