Git Interview Questions and Answers
Commits, the index and branches, merge and rebase, conflicts, undoing changes with reset, revert and reflog, remotes and pull requests, history rewriting, Git internals and team workflows.
226 questions for Git interviews with answers and explanations - Junior, Middle and Senior levels. Sample questions, online quizzes and coding tasks.
- Commits
- Branches
- Rebase
- Reset
- Workflows
Questions by level
Junior
Core concepts and syntax · 50 questions
Middle
Practice, nuances and optimization · 50 questions
Senior
Architecture, internals, edge cases · 50 questions
Sample questions
A few questions from each level with the correct answer and an explanation.
Git · Junior
- What makes Git a distributed version control system?
Correct answer: Every clone has the full history and can work offline
A clone contains every commit, so you can commit, branch and view history without a server. A remote like GitHub is just another copy that the team agrees to sync with.
- What are the three main areas a file moves through in Git?
Correct answer: Working tree, staging area (index), repository
You edit files in the working tree, choose what goes into the next commit with
git add(the index), andgit commitstores that snapshot in the repository. - What does
git add file.jsdo?Correct answer: Stages the file's current content for the next commit
git addcopies the file's current state into the index. If you edit the file again after that, the new changes aren't staged until you rungit addagain. - What does a Git commit store?
Correct answer: A snapshot of the project plus author, message and parent
Conceptually each commit is a full snapshot (unchanged files are reused, not duplicated) with metadata and a link to its parent. Diffs are computed when you ask for them.
Git · Middle
- What does
git rebase maindo on a feature branch?Correct answer: Replays the branch's commits on top of the latest
mainEach feature commit is re-applied on the new base, producing new commits with new hashes. The result is a linear history, as if you had started the branch from today's
main. - What is the "golden rule" of rebasing?
Correct answer: Don't rebase commits that others have based work on
Rebasing replaces commits with new ones. If teammates already have the old ones, their history diverges and they end up with duplicates. Your own unpushed or private branch is fine to rebase.
- Merge vs rebase for integrating
maininto a feature branch: what's the trade-off?Correct answer: Merge keeps true history; rebase gives a linear one but rewrites commits
Merge preserves exactly what happened and adds merge commits; rebase produces a clean line that's easier to read and bisect, at the cost of new hashes. Teams pick one convention.
- During a rebase you hit a conflict. What's the usual sequence?
Correct answer: Fix the files,
git addthem, thengit rebase --continueRebase stops on the commit that conflicts; once resolved and staged,
--continuemoves to the next one.--skipdrops the current commit entirely,--abortrestores the original branch.
Git · Senior
- Which four object types make up Git's object database?
Correct answer: Blob, tree, commit and annotated tag
Blobs hold file contents, trees map names to blobs and subtrees, commits point to a tree and parents, and annotated tags point to an object with a message. Branches are refs, not objects.
- Why does renaming a file not duplicate its content in Git's storage?
Correct answer: The blob is addressed by content; only the tree entry changes
Identical content always has the same hash, so it's stored once. Renames are detected later by comparing trees, not recorded explicitly.
- What is a ref in Git internally?
Correct answer: A name storing a commit hash, like
refs/heads/mainRefs live as small files or in
packed-refs.HEADis a symbolic ref pointing to another ref. Moving a branch is just writing a new hash into its ref. - What does
git gcdo?Correct answer: Packs objects, prunes unreachable ones and expires old reflogs
Loose objects are compressed into packfiles with deltas, and objects unreachable from refs and reflogs are removed after a grace period. Git runs it automatically.
Coding tasks
Write your solution right in the browser, and tests check it instantly. JavaScript interview classics (debounce, deepClone, Promise.all, an LRU cache), TypeScript tasks on generics, narrowing and utility types checked by the real compiler, Node.js backend logic (middleware, rate limiters, job queues), SQL queries in real PostgreSQL, and React components and hooks like a todo list, tabs, useDebounce and useInterval.
Open tasks →