Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Cloud & DevOps

What is the difference between git merge and git rebase?

Merge joins two branches with a merge commit and keeps history as it happened; rebase replays your commits on top of another branch for a straight line, rewriting their hashes.

Technologies
2
Difference questions
50

What each one is

git merge

Combines another branch into the current one, adding a merge commit when histories diverged.

Safe on shared branches because existing commits are untouched.

git rebase

Moves your commits to start from a new base commit.

Gives a linear, readable history; never rebase commits others already pulled.

At a glance

Aspectgit mergegit rebase
HistoryTrue, branchedLinear, rewritten
New commitsOne merge commitCopies of your commits
Safe on shared branchesYesNo
Conflict handlingOncePer replayed commit
Use forIntegrating shared branchesCleaning up your own branch

The 10 most-asked difference questions

Subjective questions 10

1What is the core difference between git merge and git rebase?Asked almost every time

Merge joins two branches and, if they diverged, adds a merge commit with two parents. Existing history stays exactly as it happened. Rebase replays your commits one by one on top of another branch. The result is a straight line, but each replayed commit gets a new hash.

2When would you choose rebase over merge, and when merge over rebase?Asked almost every time

Use rebase to tidy or update your own local or unshared feature branch before integrating it. Use merge to bring work into shared branches like main or release branches, where others have already pulled the commits. A common pattern is to rebase privately and merge publicly.

3What is the golden rule of rebasing?Asked almost every time

Never rebase commits that other people have already pulled. Rebase creates new commits with new hashes. Anyone who built on the old ones will get duplicate commits and confusing conflicts when they sync. Rebase only history that is still private to you.

4Why do commit hashes change after a rebase?Asked almost every time

A commit hash covers its content, its parent hash, the author and committer data, and the message. Rebase gives each commit a new parent and a new committer timestamp. So Git writes new commit objects with new hashes, even when the code changes are identical.

5How does conflict resolution differ between merge and rebase?Asked almost every time

Merge compares the two branch tips with their merge base, so you resolve all conflicts once, in a single step. Rebase applies commits one at a time, so the same area can conflict at several steps. You fix each one, run git add, then run git rebase --continue.

6What is a fast-forward merge?Asked almost every time

If the current branch has no commits of its own since the other branch split off, Git just moves the branch pointer forward. No merge commit is created and history stays linear. Rebasing a feature branch onto main first often makes a fast-forward merge possible.

7What is interactive rebase and what can you do with it?Asked almost every time

git rebase -i opens a todo list of commits that you can edit. You can reorder commits, squash or fixup them together, reword messages, edit their contents, or drop them. It is the standard way to clean up a branch before opening or merging a pull request.

8What is the difference between git pull and git pull --rebase?Asked almost every time

git pull fetches and then integrates the upstream changes, by merge or fast-forward unless configured otherwise. git pull --rebase fetches, then replays your local unpushed commits on top of the upstream branch. This avoids noisy commits like "Merge branch main of origin" in your history.

9How do you abort a rebase or a merge that has gone wrong?Asked almost every time

Run git rebase --abort to return the branch to where it was before the rebase started. Run git merge --abort to undo an in-progress merge that has conflicts. Both only work while the operation is still in progress, before it finishes.

10How do you recover after a rebase that you have already finished but regret?Asked almost every time

Use git reflog to find the commit your branch pointed to before the rebase, then run git reset --hard to that entry. Right after a rebase, ORIG_HEAD usually points to the old tip too. The old commits stay reachable through the reflog until garbage collection removes them.

See all 50 difference questions with answers in your dashboard →

Practise every comparison in your dashboard.

Start learning