🚀 We're LIVE on Product Hunt today — come say hi & support the launch →
All interview questions Cloud & DevOps · 2026

Git Interview Questions

Git comes up in almost every software, DevOps, and backend interview, often as a quick screen of how well you actually use version control day to day. These are the questions interviewers really ask, with concise answers you can speak confidently.

17 questions with concise, interview-ready answers.

1. What is Git, and how is it different from GitHub?

Git is a distributed version control system that tracks changes to files over time, letting you record history, branch, and collaborate. GitHub is a hosting platform built around Git that stores remote repositories and adds collaboration features like pull requests, issues, and access control. In short, Git is the tool you run locally, while GitHub (or GitLab or Bitbucket) is a service that hosts your Git repositories online.

2. How does Git differ from a centralized version control system like SVN?

In a centralized system like SVN, there is a single central server that holds the full history, and clients check out a working copy from it. Git is distributed, so every developer has a complete copy of the repository, including its full history, on their own machine. This means most operations like commits, diffs, and branching are local and fast, and you can keep working even when offline.

3. What are the working directory, the staging area, and the repository?

The working directory is the set of files you currently see and edit on disk. The staging area, also called the index, is where you assemble the exact changes you want in your next commit using git add. The repository is the .git directory that permanently stores committed snapshots and history. A commit moves the staged changes from the index into the repository as a new snapshot.

4. What is the difference between git fetch and git pull?

git fetch downloads new commits and references from the remote into your local repository but does not change your working files or current branch. git pull is essentially a fetch followed by a merge (or rebase) that integrates those remote changes into your current branch. Fetch is the safe, non-destructive way to see what is on the remote before deciding how to combine it.

5. What is the difference between merge and rebase?

Merge combines two branches by creating a new merge commit that ties their histories together, preserving the exact history of both branches. Rebase instead moves your commits so they replay on top of another branch, producing a single linear history without a merge commit. Merge keeps history truthful but can look cluttered, while rebase keeps it clean and linear but rewrites commit hashes, so you should avoid rebasing commits that others have already pulled.

6. What is the difference between git reset and git revert?

git reset moves the current branch pointer to an earlier commit, effectively removing later commits from the branch, which rewrites history. git revert instead creates a new commit that undoes the changes of a previous commit, leaving the original history intact. Revert is the safe choice for shared branches because it does not rewrite history, while reset is better for local, unpushed changes.

7. What are the three modes of git reset: soft, mixed, and hard?

git reset --soft moves the branch pointer but leaves your changes staged in the index. git reset --mixed, the default, moves the pointer and unstages the changes, but keeps them in the working directory. git reset --hard moves the pointer and discards all changes in both the index and the working directory, so it is destructive and should be used carefully.

8. What does git cherry-pick do?

git cherry-pick applies the changes from one specific commit onto your current branch, creating a new commit with the same changes but a new hash. It is useful when you want just one fix or feature from another branch without merging the entire branch. A common use is back-porting a bug fix from a development branch to a release branch.

9. What is git stash and when would you use it?

git stash temporarily shelves your uncommitted changes, both staged and unstaged, and restores a clean working directory. You use it when you need to switch branches or pull updates but are not ready to commit your current work. You bring the changes back later with git stash pop, which applies them and removes the stash, or git stash apply, which keeps the stash for reuse.

10. How do you resolve a merge conflict in Git?

A merge conflict happens when two branches change the same lines of a file in incompatible ways, and Git cannot automatically decide which to keep. Git marks the conflicting sections in the file with markers showing both versions, and you edit the file to keep the correct result and remove the markers. After fixing the files you stage them with git add and complete the merge with git commit (or git merge --continue).

11. What is HEAD, and what is a detached HEAD state?

HEAD is a pointer that refers to the current commit you are working on, usually by pointing to the tip of your current branch. A detached HEAD state occurs when HEAD points directly to a specific commit instead of a branch, for example after checking out a commit hash or a tag. In that state any new commits you make are not attached to a branch, so they can be lost unless you create a branch to keep them.

12. What is a tag in Git, and how do lightweight and annotated tags differ?

A tag marks a specific commit with a meaningful name, most often used to label release versions like v1.0. A lightweight tag is just a simple pointer to a commit with no extra information. An annotated tag is stored as a full object with a tagger name, date, message, and optional signature, which makes it the recommended choice for releases.

13. What is a fast-forward merge?

A fast-forward merge happens when the target branch has not diverged and is simply behind the branch being merged, so Git can move the branch pointer forward to the latest commit without creating a merge commit. The result is a clean linear history with no extra merge commit. You can force a merge commit even in this case with git merge --no-ff, which is useful when you want to clearly record that a feature branch was merged.

14. What is the .gitignore file used for?

A .gitignore file lists patterns for files and directories that Git should not track, such as build artifacts, dependency folders like node_modules, log files, and secrets. It keeps generated and sensitive files out of the repository so they do not clutter commits or get shared accidentally. Note that .gitignore only affects untracked files, so a file already tracked by Git must be removed from tracking before the ignore rule takes effect.

15. What does git pull --rebase do, and why use it?

git pull --rebase fetches the latest commits from the remote and then replays your local commits on top of them instead of creating a merge commit. This keeps the history linear and avoids unnecessary merge commits that clutter a shared branch. It is a common team convention because it produces a cleaner, easier-to-read history when many people work on the same branch.

16. What does it mean to squash commits, and why do it?

Squashing combines several commits into a single commit, usually done during an interactive rebase or when merging a pull request. It is used to tidy up a messy series of work-in-progress commits into one clean, meaningful commit before merging into the main branch. The result is a more readable history where each commit represents a complete, logical change.

17. What is the difference between a local branch and a remote-tracking branch?

A local branch is a branch you create and commit to on your own machine. A remote-tracking branch, such as origin/main, is a local reference that records the last known state of a branch on the remote, and it is updated by fetch or pull. You generally set a local branch to track a remote branch so that commands like git pull and git push know which remote branch to sync with.

Get these answered live in your real interview

NostrobeAI is a real-time AI interview copilot — it hears the question and drafts a strong answer on your screen, invisible on Zoom, Meet, and Teams. One-time pricing, no subscription.

Try NostrobeAI free