Git Interview Questions and Answers

Real scenario-based questions, a free 12-page Git & GitHub guide, and practice exercises — free to get started.

Free Git interview questions

A free sample — one beginner, one intermediate, one advanced — with the full answer shown below each question.

IntermediateWhat's the purpose of a `.gitattributes` file, and give one practical use for it?

It lets you control how Git treats specific files or patterns — a common practical use is normalizing line endings consistently across a team working on Windows and Linux/macOS, so line-ending differences don't show up as noisy diffs on every file someone touches.

AdvancedAn automated bot keeps opening pull requests (like dependency updates) that conflict with an in-progress large feature branch. How would you sequence merges to reduce the pain?

Merge the smaller, unrelated bot PRs into main first and regularly rebase or merge main into the large feature branch incrementally, rather than letting the feature branch sit untouched for weeks and facing one enormous conflict resolution at the end. Smaller, frequent syncs are far cheaper than one large one.

BeginnerWhat's the purpose of GitHub Environments with required reviewers configured on a deployment workflow?

It adds a manual approval gate before a GitHub Actions job can deploy to that environment (like production) — the workflow pauses and waits for an authorized reviewer to approve, giving a deliberate human checkpoint on an otherwise fully automated deployment pipeline.

Learn Git & GitHub in depth, free to start

A 12-page guide from installing Git and your first commit through rebasing, conflicts, GitHub Issues and Projects, and GitHub security (SSH keys, tokens, 2FA). The first page is free for everyone.

See the full 12-page Git & GitHub guide →

Practice Git for real, no repository at risk

Recover commits made on a detached HEAD with git reflog, revert a merged pull request on main the right way, or resolve a swapped-side rebase conflict — all graded on real Git behavior.

Try the Git & GitHub practice exercises →

Git interview FAQ

What are the most commonly asked Git interview questions?

Interviewers usually describe a real mess — a merge conflict with "ours" and "theirs" swapped, a rejected push, commits made on a detached HEAD — and ask how you'd recover, rather than asking you to define a branch from memory.

Do I need to know Git internals (the object model) for a DevOps interview?

A working understanding helps — knowing that a commit, tree, and blob are just content-addressed objects explains WHY commands like rebase and cherry-pick behave the way they do — but most interviews stay at the workflow level: branching, conflicts, recovery, not plumbing commands.

What's the difference between Git and GitHub in an interview context?

Git is the version control tool itself — it works entirely offline. GitHub is a hosting platform built around Git, adding pull requests, Issues, Actions, and team collaboration. Interviewers sometimes probe whether you understand this split, since "git revert" and "closing a PR" are not the same thing.

How do I practice Git without risking a real repository?

Work through terminal-based recovery exercises first — reverting a merged PR safely, recovering commits with git reflog, resolving a conflict the right way — graded on real Git behavior, before trying the same moves on a repository that matters.

Starting from zero? Read the step-by-step DevOps career roadmap →

The rest of the guide is waiting.

Create a free account to track your progress through the guide, pass the end-of-page quizzes, and take a full-length Git readiness check.