Interview Prep Guide
Git Interview Questions and Answers for Freshers to Experienced Developers
Prepare for Git interviews with practical questions on commits, branching, merging, rebasing, collaboration, and safe recovery strategies.
Basic Git Interview Questions
What is the difference between Git and GitHub?
Git is the version control system itself, while GitHub is a hosted collaboration platform built around Git repositories.
What is the difference between commit, push, and pull in Git?
A commit saves a snapshot in local history, push sends local commits to a remote, and pull brings remote changes into the local branch.
Why do teams use branches in Git?
Branches let developers isolate work, review changes safely, and collaborate on multiple tasks without destabilizing the main branch.
Medium Git Interview Questions
What is the difference between merge and rebase?
Merge combines histories with a merge commit, while rebase rewrites commits onto a new base to create a cleaner linear history.
When should you use git cherry-pick instead of merging a branch?
Use cherry-pick when you intentionally need one or a few specific commits, such as an isolated hotfix, without bringing in the source branch’s complete history.
What is git stash and when would you use it?
Git stash temporarily saves uncommitted changes so you can switch tasks or sync your branch without committing unfinished work.
Advanced Git Interview Questions
How would you recover safely from a bad commit, bad rebase, or accidental reset?
Use the safest recovery option for the situation, often starting with reflog, revert, or a new corrective commit rather than forcing risky history edits on shared work.
What is the difference between revert and reset?
Revert creates a new commit that undoes changes, while reset moves the branch pointer and can rewrite local history.
How do you approach resolving merge conflicts well?
Understand both branches, resolve the logic deliberately, run tests, and verify that the final code preserves the intended behavior from each side.
Scenario-Based Git Interview Questions
How would you handle a team workflow where branches are messy, releases are risky, and people keep overwriting each other’s work?
Fix the workflow conventions first: branch discipline, smaller pull requests, clearer merge strategy, and release hygiene are more important than memorizing Git commands.
Frequently Tested Git Collaboration Questions
How do merge and rebase differ?
Merge combines histories with a merge commit, while rebase replays commits onto a new base and changes their identities.
How do you recover a commit that appears lost?
Inspect reflog and object history, identify the commit, then create a branch or reset the intended local reference only after verifying the target.
When should you use git revert instead of git reset?
Use revert to undo published work by adding a new inverse commit; use reset only when deliberately moving a local reference and possibly changing its index or working tree.
How should merge conflicts be resolved safely?
Understand both intended changes, edit the combined result, run focused tests, inspect the final diff, and complete the operation only when behavior is correct.
What should happen if a secret is committed to Git?
Revoke or rotate it immediately, remove it from current code and history where required, audit use, and add prevention such as secret scanning and safer configuration.
Git Practical Round
Explain how you would fix a messy feature branch before opening a PR
Even when there is no code to write, this is still a practical round. Good answers explain a safe sequence: inspect history, clean local commits carefully, resolve conflicts deliberately, and avoid harming teammates by rewriting shared history carelessly.
Walk through the Git steps to recover from a bad merge, preserve teammate work, and reopen a clean release path
Interviewers usually care about whether you can recover safely without making the history problem worse. Strong answers explain the sequence of actions, communication with teammates, and why a certain recovery path is safer than rewriting shared history blindly.