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.
Saved automatically
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.
Related Questions in Computer Networks & OS
What happens under the hood during the TCP 3-Way Handshake and 4-Way Termination?
Intermediate level • 62 views
What is the difference between Docker Containerization and Kubernetes Container Orchestration?
Intermediate level • 59 views
How does a process differ from a thread?
Easy level • 58 views
What is virtual memory, and why is it useful even when a system has enough RAM?
Easy level • 58 views
What happens step-by-step during a DNS Lookup when typing a URL into the browser?
Intermediate level • 56 views