What is git rebase?
Why Interviewers Ask This
This is a classic screening question for Git & GitHub roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
git rebase moves or replays a sequence of commits to a new base commit. Instead of merging, it takes the commits from your branch and reapplies them one by one on top of the target branch. The result is a linear, clean history. Basic usage: while on feature branch, git rebase main — replays feature branch commits on top of the latest main. This is like saying "pretend I started working on this feature from the current tip of main." The feature branch commits get new SHA hashes (they're technically new commits with the same changes). Interactive rebase: git rebase -i HEAD~3 — open an editor to manipulate the last 3 commits. Commands in the editor: pick (keep as-is), reword (change message), edit (pause to amend), squash (combine into previous), fixup (squash silently), drop (delete commit), reorder (drag lines). Interactive rebase is powerful for cleaning up messy commit history before opening a PR — squash WIP commits into meaningful ones. Abort: git rebase --abort. Continue after resolving conflicts: git rebase --continue.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Git & GitHub codebase.