Git Interview Questions 2026: Merge vs Rebase, Reset vs Revert, and the Scenarios That Actually Get Asked
Sixteen Git questions with interviewer-grade answers — from fetch-vs-pull basics to reflog recovery and branching-strategy tradeoffs. Built for Indian freshers and 2–6 year engineers facing tech and data interviews in 2026.
By Durgesh Yadav — Senior Data Engineer @ 7-Eleven · Updated 2026-07-25. Preparation guidance, not a hiring guarantee.
What Git interview questions are asked in 2026?
Git interviews focus on daily workflow commands and recovery scenarios: merge vs rebase, reset vs revert, resolving conflicts, stash, cherry-pick, detached HEAD, and .gitignore. Freshers get command-level questions; experienced candidates get branching-strategy and history-rewriting scenarios. The strongest answers explain what happens to commit history, not just which command to type.
What interviewers actually test with Git questions
Most Git rounds are not trivia — they are a proxy for whether you have shipped code with a team. A candidate who has only made tutorial commits gets exposed the moment the question turns into a scenario: you committed to the wrong branch, a teammate force-pushed, the release needs one fix from another branch. Interviewers listen for three things. First, a mental model: do you know a branch is just a pointer to a commit, and that rebase creates new commits rather than moving old ones? Second, recovery skill: reset modes, revert, reflog, conflict resolution — proof you can get out of trouble without deleting the repo and re-cloning. Third, collaboration judgement: when force-pushing is acceptable, why shared history should never be rewritten, what a clean pull request looks like. In India, services companies and GCCs usually keep Git inside a broader coding round, while product companies push harder on scenarios and internals.
Mental model beats memorised commands: branches are pointers, commits are snapshots
Recovery skills are the differentiator: reset, revert, reflog, conflicts
Collaboration judgement: knowing what is safe on shared branches
Product companies probe deeper than services rounds — prepare one level up
How to prepare: break a repo on purpose
Reading command lists does not prepare you, because interviewers ask about consequences, not syntax. Build a scratch repository and break it deliberately. Create two branches, edit the same line in both, merge, and resolve the conflict by hand so you have seen the markers before the interview. Run git reset --hard on a commit you care about, then recover it with git reflog. Rebase a feature branch onto main and compare the SHAs before and after — you will never again say rebase 'moves' commits. Learn to read git log --oneline --graph fluently; interviewers often show history diagrams and ask what happened. Then practise saying answers aloud in the shape interviewers want: what the command does to history, when you would use it, and one pitfall. That three-beat structure works for merge vs rebase, reset vs revert, cherry-pick, and stash — which together cover most of what actually gets asked.
Force a real conflict and resolve it by hand at least once
Recover a hard-reset commit with reflog before the interview, not during
Read git log --oneline --graph until history diagrams feel natural
Answer in three beats: what it does, when to use it, one pitfall
Common mistakes that cost offers
The same mistakes appear in Git rounds every hiring season. Candidates say git pull and git fetch are the same, or describe git reset and git revert as interchangeable 'undo' commands — both are instant signals of shallow experience. Another classic: declaring rebase strictly better than merge without mentioning the golden rule that you never rebase commits others have already pulled. On conflicts, weak candidates say they 'accept incoming changes' by default, which tells the interviewer they have merged blind and broken builds before. Freshers often conflate Git with GitHub, or believe adding a file to .gitignore removes it from tracking — it does not; already-committed files need git rm --cached. Finally, avoid pretending. If your team used a simple squash-merge pull request flow, say so and explain it precisely. A sharp description of a simple workflow beats a vague description of Git Flow you have never actually run.
Never call reset and revert interchangeable
State the golden rule whenever rebase comes up
.gitignore does not untrack files that are already committed
Describe the workflow you actually used — precision beats name-dropping
Scenario questions: where the interview is decided
Beyond definitions, most interviewers reach for a small set of recovery scenarios, and each has a standard escape route worth internalising as a pattern. Committed to the wrong branch: switch to the right branch, cherry-pick the commit, then remove it from the original with reset if unpushed or revert if pushed. Need to undo a pushed commit: revert, because rewriting shared history breaks everyone else's clones. Lost work after reset --hard: the reflog still references the commit for weeks; branch it and continue. Need one fix without the rest of its branch: cherry-pick, ideally with -x for traceability. Accidentally committed a secret: revert is not enough — the value stays in history, so rotate the credential immediately and rewrite history only with team coordination. Walking through the reasoning — what state the repo is in, what is shared, what is safe — is exactly what separates an experienced answer from a memorised one.
Wrong-branch commit: cherry-pick across, then reset or revert the original
Lost commits: reflog keeps local history recoverable for weeks
Pushed mistakes: revert; committed secrets: rotate the credential first
Always state whether history is shared before choosing a fix
Question bank
16 interview questions with answers
Real questions from beginner to advanced, each with a concise model answer — practice them, then rehearse live in a mock interview.
EasyWhat is Git, and how is it different from GitHub?
Git is a distributed version control system. It records snapshots of your project as commits, and every clone contains the complete history, so you can commit, branch, diff, and inspect history entirely offline. GitHub is a hosting service built around Git: it stores remote copies of repositories and adds collaboration features — pull requests, code review, issues, access control, and CI integration. Nothing in Git requires GitHub; you could push to GitLab, Bitbucket, or a bare repository on your own server and Git behaves identically. Interviewers ask this to catch candidates who conflate the two, which suggests they have only clicked through a web UI. A crisp answer states the split in one line — Git is the tool, GitHub is a place to host Git repositories plus a collaboration layer — and adds that commits are local until you push.
EasyWhat is the difference between git fetch and git pull?
git fetch downloads new commits, branches, and tags from the remote and updates your remote-tracking references, such as origin/main, without changing your current branch or working files. git pull is fetch plus integration: it fetches, then merges the remote branch into your current branch — or rebases onto it if you use pull --rebase or set pull.rebase in config. The practical difference is control. After a fetch you can inspect what arrived — git log main..origin/main shows incoming commits — and then integrate deliberately. Pull integrates immediately, which can produce surprise merge commits or conflicts mid-task. A good habit worth stating: fetch frequently, pull deliberately. Also note that pull only updates the branch you are currently on; your other local branches stay where they were until you update them separately.
EasyWhat does git init do compared to git clone?
git init creates a brand-new, empty repository by writing a .git directory into the current folder. There is no history, no remote, and no commits until you make the first one. git clone copies an existing repository: it downloads the full history from a source URL, creates the .git directory, sets up a remote named origin pointing back at the source, creates remote-tracking branches, and checks out the default branch into your working directory. So init starts a project from scratch, while clone gives you a complete local copy of an existing one. A detail that shows depth: because clones carry full history, every developer's machine is effectively a backup of the entire project — a core consequence of Git being distributed rather than centralised like older systems such as SVN.
EasyWhat is .gitignore, and what should go in it?
.gitignore is a file of patterns telling Git which untracked files to ignore, so they never appear in git status or get swept into commits by git add . Typical entries: build outputs, dependency folders like node_modules or a Python venv, logs, IDE settings, OS junk like .DS_Store, and environment files such as .env that hold secrets. Two details separate strong answers. First, .gitignore only affects untracked files — if a file is already committed, adding it to .gitignore changes nothing; you must run git rm --cached on it to stop tracking while keeping it on disk. Second, a secret that was ever committed lives on in history even after removal, so the credential must be rotated. Mentioning a global ignore file via core.excludesFile for personal editor cruft is a nice extra.
EasyWhat is the staging area, and why does Git have it?
Git has three zones: the working directory where you edit, the staging area (also called the index), and the repository of committed snapshots. git add copies the current state of a file into the index; git commit records exactly what the index contains as a new commit. The middle layer exists so you can compose commits deliberately. You might edit five files but stage and commit only two, or use git add -p to stage individual hunks within a file, producing small, reviewable commits instead of one tangled dump. It also explains commands that confuse beginners: git diff shows working directory versus index, while git diff --staged shows index versus the last commit. Tying the staging area to commit hygiene — small, focused commits reviewers can follow — shows you actually use it, not just know of it.
MediumExplain merge vs rebase. When would you use each?
Merge joins two lines of history with a merge commit that has two parents. Nothing existing is rewritten, so it is always safe, and history honestly records that parallel work happened — at the cost of a busier graph. Rebase takes your branch's commits and replays them one by one on top of a new base, creating new commits with new SHAs; the originals are abandoned. You get clean, linear history, but it is history rewriting. Hence the golden rule: never rebase commits others may have already pulled, because their history no longer matches yours and everyone must recover manually. A common professional workflow: rebase your local, unpushed feature branch onto the latest main to stay current, then integrate into main through a pull request using a merge or squash-merge. Presenting this as a tradeoff, not a winner, is what interviewers want.
MediumWhat is the difference between git reset and git revert?
git reset moves the current branch pointer to another commit, rewriting history. Its modes control what happens to your files: --soft keeps changes staged, --mixed (the default) keeps them in the working directory but unstaged, and --hard discards them entirely. Because the abandoned commits become unreachable from the branch, reset belongs on local, unpushed work. git revert does the opposite of rewriting: it creates a new commit whose diff is the inverse of the target commit, so both the mistake and its correction remain in history. That makes revert the only safe way to undo something already pushed to a shared branch. A crisp summary: reset rewrites, revert appends. Bonus credit for noting that commits 'lost' to a reset are usually recoverable through git reflog for a while, since Git does not delete them immediately.
MediumWhat is git stash, and when would you use it?
git stash shelves your uncommitted changes — staged and unstaged modifications to tracked files — onto a stack and restores a clean working directory. Classic uses: switching branches for an urgent fix, or pulling changes that would conflict with half-done work. git stash pop reapplies the latest stash and drops it; git stash apply reapplies but keeps the entry, which is safer when the reapply might conflict. Untracked files are not stashed unless you pass -u, a detail that catches people out. Also useful: git stash list shows the stack, and git stash branch creates a branch from a stash — handy when stashed work no longer applies cleanly to the current branch. The honest caveat interviewers like: stashes are invisible and easy to forget, so for anything beyond a quick interruption, a WIP commit on a branch is more recoverable.
MediumWhat is git cherry-pick, and when is it appropriate?
git cherry-pick <sha> takes the change introduced by one specific commit and applies it to your current branch as a brand-new commit with a new SHA. It is the right tool when you need a single change without everything else on its branch — most commonly backporting a bug fix from main to a release branch, or rescuing one good commit from an abandoned branch. Using -x appends the original commit reference to the message, keeping backports traceable. The costs are worth stating: the same change now exists as two different commits, which can cause conflicts when the branches eventually merge, and cherry-picking a commit that depends on earlier commits you skipped will conflict or silently miss context. It is a precision tool, not a merging strategy — if you need many commits from a branch, merge or rebase instead.
MediumHow do you resolve a merge conflict?
A conflict occurs when two branches change the same lines, or one deletes a file the other modifies, so Git cannot pick a side automatically. The merge stops, git status lists unmerged paths, and each conflicted file contains markers: your side between <<<<<<< and =======, the incoming side between ======= and >>>>>>>. The process: open each file, decide what the combined code should actually be — one side, both, or something new — delete the markers, run tests if possible, then git add the resolved files and finish with git commit or git merge --continue. During a rebase you repeat this per conflicted commit with git rebase --continue. If things go sideways, git merge --abort or git rebase --abort restores the previous state. Mention prevention too: small pull requests and frequently syncing your branch with main shrink conflicts dramatically.
MediumWhat is detached HEAD state, and how do you recover from it?
HEAD normally points at a branch name, and the branch points at a commit, so new commits advance the branch. When you check out a commit hash or tag directly, HEAD points straight at the commit with no branch attached — detached HEAD. It is not an error; it is how you inspect an old version, and how CI systems check out exact commits. The danger is committing there: those commits belong to no branch, and once you switch away they become unreachable and eventually eligible for garbage collection. Recovery is simple. If you are still on the commits, run git switch -c rescue-branch and the work is safe. If you already switched away, git reflog shows the commit you were on; create a branch from that SHA. Saying 'create a branch before leaving' is the line interviewers listen for.
MediumDescribe a typical pull request workflow, including merge strategies.
Branch off the latest main with a descriptive name, make small focused commits, and push the branch. Open a pull request; CI runs tests and linting automatically. Reviewers comment; you push fixes, and when the branch falls behind you update it by merging main into it or rebasing onto main. Once approved and green, it merges using one of three strategies. A merge commit preserves every commit and the branch structure. Squash-merge collapses the PR into a single commit on main — popular because main stays readable and each commit maps to one reviewed change. Rebase-merge replays the PR's commits onto main individually, keeping detail with linear history. Afterwards, delete the branch. Strong answers add the habits that make this work: PRs small enough to review properly, a clear description, and never force-pushing the shared target branch.
HardHow does Git store data internally?
Git is a content-addressed object database under .git/objects with four object types. Blobs hold file contents. Trees represent directories, mapping names to blobs and other trees. Commits point to one tree — the snapshot of the whole project — plus parent commit(s), author, and message. Annotated tags wrap another object with a name and message. Every object's ID is a hash of its content (SHA-1 historically; newer Git also supports SHA-256), so identical content is stored once and no object can change without changing its ID. Branches are not copies of anything — a branch is a file in .git/refs/heads containing one commit hash, and HEAD points to the current branch. This model explains everyday behaviour: branching is instant, commits are immutable, amending or rebasing actually creates new commits, and history rewrites are disruptive because they change hashes everything else references.
HardWhat is git reflog, and how does it help you recover lost work?
The reflog is a local journal of where HEAD and each branch tip have pointed, recorded every time they move — commits, checkouts, resets, rebases, merges. Its power is that commits abandoned by history rewrites remain reachable through it. After an accidental git reset --hard, git reflog shows entries like HEAD@{2} with the commit you were on; recover with git reset --hard HEAD@{2} or, more safely, git branch rescue <sha>. The same trick recovers a botched rebase or a deleted branch. Its limits matter in a strong answer: the reflog is purely local — never pushed, so it cannot help on another machine — and entries expire, by default after 90 days for reachable entries and 30 for unreachable ones, after which garbage collection can remove the commits. It also cannot restore work that was never committed or staged.
HardA bad commit was pushed to a shared branch. How do you undo it?
Default answer: git revert <sha>, which adds a new commit inverting the bad change. History is not rewritten, so nobody's clone breaks, and the fix goes through the normal push or PR flow. Reverting a merge commit needs -m 1 to specify the mainline parent. The alternative — reset and force-push — rewrites shared history and forces everyone who pulled the branch to recover, so it is reserved for branches only you use, or an explicitly coordinated team decision; when forcing, use --force-with-lease so you cannot overwrite commits you have not seen. The special case worth raising unprompted: if the commit exposed a secret, revert is insufficient because the value remains in history. Rotate the credential immediately; truly purging it requires a history rewrite with a tool like git filter-repo plus coordination with everyone who has a clone.
HardCompare Git Flow and trunk-based development. How do you choose?
Git Flow uses long-lived main and develop branches plus feature, release, and hotfix branches. It gives explicit release staging and suits products with versioned, scheduled releases — but long-lived branches drift apart, merges get large, and integration problems surface late. Trunk-based development inverts this: everyone merges small changes into main within a day or two, incomplete features hide behind feature flags, and main stays releasable — which is what continuous deployment needs. Its prerequisite is discipline: strong automated tests, fast CI, and small PRs, because a broken main blocks everyone. Many teams actually run the lighter middle option, GitHub Flow: branch, PR, review, merge to main, deploy. The interview-winning move is choosing by context — release cadence, CI maturity, team size, and whether you ship versions or a continuously deployed service — then describing which model your team used and how it worked in practice.
Related Guides
Keep Preparing
Move between roadmaps, interview questions, and tools without losing your preparation thread.
Do data engineer and data analyst interviews ask Git questions?
Yes, at different depths. Data engineers are expected to answer close to software-engineer level — branching, merge vs rebase, conflict resolution, and PR workflow — because pipeline code lives in version-controlled repos with CI. Data analysts usually face workflow-level questions: clone, branch, commit, pull, push, often to check whether they can collaborate on dbt models or notebooks. Either way, being unable to describe basic branching is a red flag interviewers act on.
How many Git questions should a fresher prepare for?
Expect two to five Git questions inside a broader technical round rather than a dedicated Git interview. The core list is small: fetch vs pull, merge vs rebase, reset vs revert, stash, cherry-pick, conflicts, .gitignore, and detached HEAD. Preparing those deeply matters more than covering fifty questions shallowly, because interviewers follow up with 'what if' scenarios, and a memorised one-liner collapses under the second question.
Merge vs rebase — which answer do interviewers want?
Neither as a winner. They want the tradeoff: merge preserves true history and is safe on shared branches; rebase gives linear history but creates new commits, so it must never touch commits others have already pulled. A strong close describes a real workflow — rebase your local feature branch onto main, then merge or squash-merge the pull request. Declaring one option 'better' without conditions invites a follow-up you will lose.
Do I need Git internals like objects and refs for interviews?
For fresher and services-company rounds, rarely. For product companies and 2–6 year backend roles, a working model helps: Git stores blobs, trees, and commits in a content-addressed object store, and a branch is just a file containing a commit hash. You do not need packfile or delta-compression detail. Internals answers earn credit because they explain visible behaviour — why rebase changes SHAs, why branching is instant, why history rewrites disrupt teams.
What is the fastest way to practise Git scenarios before an interview?
Make a throwaway repository and break it deliberately for an hour. Force a conflict by editing the same line on two branches, then resolve it. Hard-reset a commit, then recover it from reflog. Check out a raw commit hash to see detached HEAD, and branch your way out. Rebase a branch and compare hashes before and after. One hour of deliberate breakage produces more convincing answers than a week of reading command references.
Next Step
Turn The Guide Into Practice
Use PrepNPlaced tools to turn this learning path into resume proof, targeted practice, and interview-ready explanations.