Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

git

What is the git rebase <branch name> command?

Talha Ashar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

RELATED TAGS

git

CONTRIBUTOR

Talha Ashar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring