What is the difference between git merge and git rebase? When should you use each?
Suggested answer
Both bring changes from one branch into another, but they record history in two different ways.
git mergecreates a merge commit that joins the two branches. History stays as it happened, and you can see exactly when the branch split off and came back.git rebaserewrites your branch's commits on top of the target branch. History becomes a straight line that is easier to read, but the commits get new hashes.
git switch feat/login
git fetch origin
git rebase origin/main # straight history; only do this on a branch that is yours aloneIn an interview, mentioning the trade-off (true history versus readable history) and the rule your team actually follows earns more points than the definitions alone.