Sobes.tech
Junior — Middle

Can you explain how the rebase command works in Git?

sobes.tech AI

Answer from AI

The git rebase command allows you to move (replay) commits from the current branch onto a new base — another branch or commit. It's like "moving" the start of your branch to make the history more linear and clean.

Example:

# Switch to the feature branch
git checkout feature

# Rebase the feature branch onto the master branch
git rebase master

As a result, all commits from feature will be applied on top of the current state of master. This helps avoid unnecessary merge commits and simplifies the history.

Important: when working collaboratively with other developers, be cautious with rebase to avoid rewriting shared history.