What is the git rebase <branch name> command?

The git rebase <branch name> command integrates changes from one branch into another. It moves the currently active branch to join the tip of the specified target branch.

The git rebase <branch name> command also rewrites the project history by creating new commits in the target branch.

The process is illustrated below:

Options

The options of the git rebase <branch name> command are as follows:

  • <branch name>: The target branch to which commits from the currently active branch must be integrated.

Usage

The commands below demonstrate how you can integrate changes from one branch (feature) into another branch (main):

git checkout feature
git rebase main

The command git checkout switches to the feature branch as your currently active branch. The git rebase main command adds commits from the feature branch to the tip of the main branch.

When working on public branches, you should avoid using the git rebase <branch name> command. Since rebasing re-writes the project history, your branch may diverge from the one other developers have.

Note: For more details and variants of the git rebase command, you can check the official documentation.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved