Verified Jobs Live
Computer Networks & OS Beginner Level ~3 min read

What is the difference between 'git merge' and 'git rebase', and when should each be used in a team workflow?

Quick Revision Summary

Git Merge preserves branch history with merge commits; Git Rebase rewrites commits for a linear history. Never rebase shared public branches.

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

Git Merge:

  • Combines changes by creating a new 3-way merge commit connecting the two branches.
  • Pros: Non-destructive. Preserves complete, truthful historical record and exact chronological order of commits.
  • Cons: Branch commit history can become cluttered with numerous merge commits in large teams.

Git Rebase:

  • Rewrites commit history by moving the entire feature branch to begin from the tip of the base branch, re-applying each commit sequentially.
  • Pros: Produces a clean, linear git history without unnecessary merge commits.
  • Golden Rule: Never rebase commits that have been pushed to a public/shared branch, as it rewrites commit SHAs and causes divergence for teammates.

Interviewer Evaluation Points & Scoring Rubric

  • 1 1. Explains 3-way merge commit vs history rewriting. 2. Stresses the golden rule of never rebasing public branches. 3. Recommends team workflow hygiene.