Sobes.tech
Junior — Middle

What is the purpose of the git rebase command and in what scenarios is it used?

sobes.tech AI

Answer from AI

The git rebase command is used to transfer or 'rewrite' a series of commits onto a new base. This makes the commit history more linear and clean.

Main use cases:

  • Updating a feature branch based on the current main/master branch: Instead of merging, rebase moves your commits on top of the latest changes from the main branch, simplifying the history.

  • Cleaning up commit history: You can squash, modify, or delete commits before pushing to a shared repository.

Example:

# Rebase the current branch onto the main branch
git checkout feature
git rebase main

Important: When using rebase on public branches, be careful not to rewrite history that others are already using.