Sobes.tech
Junior — Middle

What is the purpose of the git rebase command and how does it differ from merge?

sobes.tech AI

Answer from AI

The git rebase command is used to transfer or 'rewrite' a series of commits onto a new base, meaning it allows you to take changes from one branch and apply them on top of another branch. This helps maintain a linear commit history without additional merges.

Differences from git merge:

  • git merge combines two branches, creating a new merge commit, while preserving the entire branch history.
  • git rebase moves commits from one branch onto the tip of another, rewriting history and making it more linear.

Example:

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

After this, the history will look as if all changes in feature were made after the latest commits in master, without merge commits.