← All topics

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.

Questions by level

Sample questions

A few questions from each level with the correct answer and an explanation.

Git · Junior

  1. 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.

  2. 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), and git commit stores that snapshot in the repository.

  3. What does git add file.js do?

    Correct answer: Stages the file's current content for the next commit

    git add copies the file's current state into the index. If you edit the file again after that, the new changes aren't staged until you run git add again.

  4. 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.

All 75 questions with answers →

Git · Middle

  1. What does git rebase main do on a feature branch?

    Correct answer: Replays the branch's commits on top of the latest main

    Each 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.

  2. 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.

  3. Merge vs rebase for integrating main into 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.

  4. During a rebase you hit a conflict. What's the usual sequence?

    Correct answer: Fix the files, git add them, then git rebase --continue

    Rebase stops on the commit that conflicts; once resolved and staged, --continue moves to the next one. --skip drops the current commit entirely, --abort restores the original branch.

All 75 questions with answers →

Git · Senior

  1. 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.

  2. 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.

  3. What is a ref in Git internally?

    Correct answer: A name storing a commit hash, like refs/heads/main

    Refs live as small files or in packed-refs. HEAD is a symbolic ref pointing to another ref. Moving a branch is just writing a new hash into its ref.

  4. What does git gc do?

    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.

All 76 questions with answers →

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 →