Home
All articles
GitVersion ControlInterview PrepDevOps

100 Git Interview Questions & Answers

August 19, 202660 min read

Git interviews test whether you understand the underlying object model, not just which commands to type — why a rebase rewrites history and a merge doesn't, what actually happens during a merge conflict, why git pull is really two commands wearing a trenchcoat. This covers all 100 questions, organized by topic, with commands, a diagram, and a mock test at the end.

0 / 100 blocks read

Git Fundamentals

Q1. What is Git and why is it used?

Git is a distributed version control system that tracks changes to files over time, letting multiple people work on the same codebase concurrently, branch off to work in isolation, and merge changes back together — used because it's the industry-standard way to manage source code history, enable collaboration, and recover from mistakes (nothing is truly lost as long as it's committed somewhere).

Q2. How does Git differ from other version control systems (VCS)?

Centralized VCS (e.g. old SVN)Git (distributed)
Repository copiesOne central server holds the full historyEvery clone has the FULL history locally
Offline workLimited — most operations need the serverCommit, branch, view history, all fully offline
SpeedMost operations require a network round tripMost operations are local and near-instant

Q3. What is the difference between Git and GitHub?

GitGitHub
What it isThe version control tool/protocol itselfA hosting platform built around Git repositories
Runs whereLocally, on your machineIn the cloud, as a service
AddsNothing extra — it's the core toolPull requests, issues, Actions (CI/CD), code review UI

Git works completely independently of GitHub — you can use Git with no GitHub account at all (a local repo, or hosted on GitLab, Bitbucket, or your own server). GitHub is one of several popular hosting services built on top of Git, adding collaboration features Git itself doesn't provide.

Q4. What is a repository in Git?

A repository (repo) is the full set of files, folders, and their complete commit history, tracked by Git in a hidden .git directory at the project's root — that .git folder IS the repository; deleting it removes all Git tracking while leaving the working files themselves intact.

Q5. Explain the concept of a commit in Git.

bash
git add file.txt
git commit -m "Add feature X"

A commit is a permanent, addressable snapshot of the entire tracked project at a point in time, along with metadata (author, timestamp, message, and a pointer to its parent commit(s)) — commits form a chain (or graph, once branching enters the picture) that constitutes the project's history.

Q6. What is the difference between a working directory, staging area, and repository in Git?

The three states a file's changes pass through

Working directory

Your actual files on disk, edited freely

Staging area (index)

git add — changes marked for the next commit

Repository

git commit — changes permanently recorded in history

The working directory is where you actually edit files; git add moves selected changes into the staging area (a preview of exactly what the next commit will contain); git commit takes everything staged and permanently records it into the repository's history. This three-stage model is what lets you commit only part of your current changes, not everything you've touched.

Q7. Define branching in Git and its importance.

bash
git branch feature-x
git checkout feature-x
# or in one step:
git checkout -b feature-x

A branch is an independent, movable pointer to a commit — creating one lets you develop a feature or fix in isolation without affecting the main line of history, and merge it back only once it's ready. This is what makes parallel, non-blocking collaborative development practical.

Q8. What is a HEAD in Git?

HEAD is a pointer to whatever commit you currently have checked out — normally it points to a branch (which itself points to a commit), so HEAD moves along automatically as you commit on that branch; checking out a specific commit directly (rather than a branch) puts you in a "detached HEAD" state.

Q9. What does the 'clone' operation in Git do?

bash
git clone https://github.com/user/repo.git

git clone copies an entire remote repository — every commit, branch, and tag in its full history — down to a new local directory, and automatically sets up that remote as origin, ready to push/pull against.

Q10. How does Git store information?

Git stores content as a graph of four object types, all content-addressed by SHA-1 (or SHA-256 in newer repos) hash: blobs (raw file content), trees (directory listings, mapping names to blob/tree hashes), commits (a snapshot pointer plus metadata and a parent link), and tags (a named pointer to a specific commit). Crucially, Git doesn't store per-file diffs — every commit points to a full snapshot of the entire tree, with unchanged files simply reusing the same blob hash they already had.

Page110