How do i perform a git rebase?

  • Link for understanding rebasing from git documentation:

    Quote from git documentation: "Do not rebase commits that exist outside your repository and people may have based work on them."

    Note: The general advice is you should know what you are trying to achieve when using this command.

    The diagrams are from git documentation, their demo shows different branch names.

    If you create a branch from master in your local, for example named crufts2020 and start making changes, those changes will be divergent from the master.

    Create a branch from master branch.

    $ git checkout -b crufts2020
    Switched to a new branch 'crufts2020'

    Start making some changes. in crufts2020 and your commit history should look something like this:


    Rebase changes from crufts2020 branch on master branch.

    $ git rebase master
    First, rewinding head to replay your work on top of it...
    Applying: Added another perl script for staging

    After the rebase your commit history should look something like:


    Perform a fast-forward merge on master.

    $ git checkout master
    $ git merge crufts2020
    Updating 0f307e7c9b..d6d7656542
    Fast-forward | 2 ++
     1 file changed, 2 insertions(+)
     create mode 100644

    After the fast-forward merge your commit history should look something like:


    All commits have been replayed onto master and both branches now point to the same commit.

Log in to reply

© Lightnetics 2020