QA Interview
Git Interview Questions for QA Engineers
Git interview questions for QA engineers, with real commands and answers covering merge vs rebase, conflict resolution, undoing changes safely, and git bisect.
2,598 words | Article schema | FAQ schema | Breadcrumb schema
Overview
Automation code is code, and code lives in Git. The moment your tests share a repository with the application (or even their own repo), you are expected to branch, commit, review, and resolve conflicts like any engineer. Interviewers know this, so QA and SDET loops almost always include a Git round, and fumbling basic commands undercuts an otherwise strong automation candidate.
This guide is for QA engineers who use Git every day but may not have studied it formally. It covers the commands and concepts that come up in interviews, framed around the situations testers actually hit: a merge conflict in a page object, a regression you need to trace to a single commit, a half-finished test you need to shelve. Every answer is written the way you should say it out loud.
You will get real questions with strong answers, the exact commands to name, and one genuinely QA-specific superpower most candidates forget: using `git bisect` to pinpoint the commit that introduced a bug. Learn that one and you will stand out from testers who treat Git as just save and push.
Why Git Fluency Matters for QA
Interviewers ask testers about Git for the same reason they ask about CI: they want proof you work inside a real engineering process, not off to the side. If your automation lives in the same repo as the app, you branch off it, open pull requests, review diffs, and untangle conflicts alongside developers. A tester who can do that fluently reduces friction for the whole team, and that is what the Git round is really measuring.
There is a credibility angle too. Nothing undermines a confident automation answer faster than freezing on how to undo a bad commit or resolve a conflict. Conversely, casually naming the right command for a messy situation tells the interviewer you have lived in version control under pressure. The bar is not Git-wizard depth; it is calm, correct fluency with the everyday operations plus a couple of recovery tricks.
- Automation code is reviewed and merged like any other code.
- Git fluency reduces friction between QA and developers.
- Freezing on undo or conflict questions undercuts strong automation answers.
- The bar is calm everyday fluency plus a few recovery commands.
Core Concepts You Must Nail
Interviewers open with fundamentals to calibrate you, so be crisp. Git is a distributed version control system, meaning every clone is a full repository with complete history, not just a checkout. The three states to name are the working directory (your files), the staging area or index (changes marked for the next commit via `git add`), and the repository (committed history). A commit is an immutable snapshot identified by a SHA hash; `HEAD` is a pointer to the commit you currently have checked out.
A common follow-up is the difference between local and remote. Your commits live locally until you `git push`; `origin` is the default name for the remote you cloned from. Emphasize that because Git is distributed, you can commit, branch, and view history fully offline, which is exactly why it scales to large teams working in parallel without stepping on each other.
- Three states: working directory, staging area (`git add`), and committed history.
- A commit is an immutable snapshot with a SHA; `HEAD` points at your current commit.
- Every clone is a full repo with complete history (distributed).
- `origin` is the default remote; commits are local until you `git push`.
Everyday Commands They Expect
Expect rapid-fire command recall. Know these cold: `git status` (what changed and what is staged), `git add` (stage), `git commit -m 'message'` (record), `git push` and `git pull` (sync with the remote), `git log --oneline` (compact history), and `git diff` (unstaged changes) versus `git diff --staged` (what a commit would contain). Being smooth here sets the tone for the whole round.
The gotcha they often probe is `fetch` versus `pull`. `git fetch` downloads remote changes without touching your working files, letting you inspect before integrating. `git pull` is `fetch` plus an automatic `merge` (or `rebase` if configured) into your branch. Saying that `pull` is a compound command shows you understand what it actually does, which matters when a surprise merge commit or conflict appears out of nowhere.
- `git status`, `git add`, `git commit -m`, `git push`, `git pull` are the daily core.
- `git log --oneline --graph` reads history fast in an interview.
- `git diff` shows unstaged; `git diff --staged` shows the next commit contents.
- `fetch` downloads only; `pull` equals `fetch` plus `merge`.
Branching and Merging
Branching is cheap in Git and central to how QA works: a branch per feature or per test task. Name the commands: `git branch feature-x` creates one, `git switch feature-x` (or the older `git checkout`) moves onto it, and `git switch -c feature-x` does both. A branch is just a movable pointer to a commit, which is why creating one is instant.
For merging, know fast-forward versus a merge commit. If the target branch has not moved, Git simply advances the pointer (a fast-forward). If both branches have new commits, Git creates a merge commit that ties the histories together. Mention `git merge --no-ff` when a team wants an explicit merge commit to preserve where a feature branch began, a common convention in review-heavy workflows.
- `git switch -c feature-x` creates and moves onto a new branch in one step.
- A branch is a lightweight movable pointer, so branching is cheap.
- Fast-forward advances the pointer; a merge commit joins diverged histories.
- `--no-ff` forces a merge commit to preserve feature-branch boundaries.
Merge vs Rebase: The Depth Question
This is the Git question most likely to expose depth. Both integrate changes from one branch into another, but differently. `git merge` preserves history exactly and creates a merge commit, so the graph shows the true branching. `git rebase` replays your commits on top of the target branch, producing a linear history with no merge commit, as if you had branched from the latest tip.
State the golden rule clearly: never rebase commits that have been pushed and that others may have based work on, because rebase rewrites SHAs and will diverge from their history. Rebase is great for tidying your own local branch before opening a pull request; merge is safer for shared branches. Interviewers reward this trade-off far more than a textbook definition.
- Merge preserves true history with a merge commit; rebase makes it linear.
- Rebase rewrites commit SHAs by replaying them on the new base.
- Golden rule: never rebase commits others have already pulled.
- Rebase your local branch to tidy up; merge shared branches.
Stash, Cherry-pick, and Reset
These three come up as practical follow-ups. `git stash` shelves your uncommitted changes and reverts to a clean working directory, so you can switch branches to reproduce a bug, then run `git stash pop` to bring your work back. Testers use this constantly when a hotfix interrupts a half-written test and you need a clean tree fast.
`git cherry-pick <sha>` copies a single commit onto your current branch, useful for pulling one specific fix into a release branch without merging everything. Explain `git reset` at a high level here (it is covered in depth next): it moves the branch pointer, with `--soft` keeping changes staged, `--mixed` keeping them in the working directory, and `--hard` discarding them entirely.
- `git stash` and `git stash pop` shelve and restore work in progress.
- `git cherry-pick <sha>` copies one commit onto the current branch.
- `git reset --soft` keeps changes staged; `--mixed` unstages; `--hard` discards.
- Cherry-pick a single fix into a release branch without a full merge.
Undoing Mistakes Safely
Undo questions test whether you will destroy shared history. The key distinction: `git revert <sha>` creates a new commit that undoes a previous one, which is safe on shared branches because it adds history rather than rewriting it. `git reset` moves the branch pointer backward and can discard commits, which is fine locally but dangerous on anything already pushed.
Your safety net is `git reflog`, which records where HEAD has been even after a reset or a bad rebase. If you run `reset --hard` and panic, `reflog` shows the lost commit SHA so you can recover it with `git reset --hard <sha>` or a checkout. Naming reflog unprompted signals real Git experience, because usually only people who have made the mistake know it exists.
- `git revert` adds an undo commit and is safe on shared branches.
- `git reset` rewrites the pointer; keep it to local, unpushed work.
- `git reflog` recovers commits lost to a bad reset or rebase.
- Rule of thumb: revert in public, reset in private.
git bisect: The Tester's Superpower
Here is the question few candidates nail and the one that marks you as a tester who thinks in root cause. Prompt: a test passes on an old build and fails on the latest; how do you find the exact commit that broke it? Answer: `git bisect`, a binary search through history. You mark a known-good and a known-bad commit and Git checks out the midpoint for you to test, halving the search space each step. You run `git bisect start`, then `git bisect bad` on the current commit, then `git bisect good <old-tag>`, test the checkout, and mark it good or bad until Git names the first bad commit.
You can even automate it: `git bisect run npm test` lets Git drive the whole search using your test exit code, pinpointing the culprit commit across hundreds of changes in minutes. That is a QA-native use of Git most developers underuse, and calling it out lands hard in an interview because it reframes Git from bookkeeping into a debugging tool.
- `git bisect` binary-searches history for the commit that introduced a bug.
- Mark one good and one bad commit; Git checks out midpoints for you to test.
- `git bisect run <cmd>` automates the search using the command exit code.
- It turns days of guessing into minutes of structured search.
Resolving Conflicts in Test Code
Merge conflicts are inevitable when several people edit the same page object or config. Walk through the flow calmly: after a `merge` or `rebase` reports a conflict, `git status` lists the conflicted files. Open each, find the `<<<<<<<`, `=======`, and `>>>>>>>` markers, and edit to the correct combined result rather than blindly keeping one side. Then `git add` the resolved file and continue with `git commit` for a merge or `git rebase --continue` for a rebase.
For QA specifically, mention that conflicts in generated files, lockfiles, or test reports are best prevented by gitignoring artifacts, and that repeated conflicts in a shared helper are a smell that the framework needs better modularity. If you are unsure which change is right, you talk to the other author rather than guessing; a wrongly resolved conflict in a base class can silently break dozens of tests at once.
- `git status` lists conflicts; edit the `<<<<<<<`, `=======`, `>>>>>>>` markers.
- Combine both sides correctly, then `git add` and continue.
- Prevent noise by gitignoring reports, screenshots, and build artifacts.
- When unsure, ask the other author; a bad base-class merge breaks many tests.
Collaboration, Branching Strategy, and PRs
Interviewers want to see you work well on a team. Describe a branching strategy: short-lived feature branches off `main` (or a trunk-based flow), a pull request for review, CI running the suite on the PR, and merge only when green and approved. Emphasize small, focused commits with clear messages, because your commit history is documentation the next tester reads.
Bring up `.gitignore` unprompted for credibility. Test suites generate noise: `node_modules/`, `target/`, `test-results/`, screenshots, videos, and `.env` files with secrets. All of that belongs in `.gitignore` so it never pollutes the repo or leaks credentials. A candidate who mentions keeping secrets and artifacts out of version control shows security awareness on top of Git skill.
- Short-lived branches, a PR, CI on the PR, merge when green and approved.
- Small focused commits with clear messages; history is documentation.
- `.gitignore` build output, `node_modules/`, reports, videos, and `.env`.
- Keeping secrets out of Git is both hygiene and security.
Scenario and Behavioral Questions
Scenario: you committed to the wrong branch. Calm answer: if it is not pushed, move the commits with `git cherry-pick` onto the right branch and `git reset --hard` the wrong one, or create the correct branch with `git switch -c` before resetting. Scenario: you accidentally committed a secret. You rotate the secret immediately (assume it is compromised), then purge it from history with a tool like `git filter-repo`, and add it to `.gitignore`. Rotating first is the part juniors forget.
Behavioral prompts probe collaboration: describe a time a teammate force-push wiped your work, or how you handle a messy history. Show that you favor communication and safe commands (revert, reflog) over heroics, and that you would rather protect shared branches, even with branch protection rules, than clean up after avoidable rewrites. Judgment and safety beat command trivia every time.
- Wrong branch: cherry-pick to the right one, then reset the wrong one (if unpushed).
- Committed a secret: rotate it first, then purge history and gitignore it.
- Prefer revert and reflog over force-pushes on shared branches.
- Protect shared branches so avoidable rewrites cannot happen.
Frequently Asked Questions
What Git questions are asked in QA interviews?
Expect fundamentals (staging, commits, HEAD), everyday commands, branching and merging, the merge versus rebase trade-off, undoing changes safely, and conflict resolution. Many loops also include a practical scenario like recovering a lost commit or tracing a regression to a specific commit.
What is the difference between git merge and git rebase?
Merge integrates branches and records a merge commit, preserving the true history. Rebase replays your commits onto the target branch for a linear history but rewrites commit SHAs. Never rebase commits others have already pulled; rebase is for tidying your own local branch.
How do you resolve a merge conflict in Git?
Run `git status` to see conflicted files, open each, and edit the conflict markers into the correct combined result. Then `git add` the file and finish with `git commit` for a merge or `git rebase --continue` for a rebase. When unsure which side is right, ask the other author.
What is the difference between git reset and git revert?
`git revert` creates a new commit that undoes a previous one and is safe on shared branches. `git reset` moves the branch pointer and can discard commits, which is fine for local, unpushed work but dangerous on anything already pushed. Revert in public, reset in private.
How can a tester find which commit introduced a bug?
Use `git bisect`, a binary search through history. Mark a known-good and a known-bad commit and Git checks out midpoints for you to test. You can automate it with `git bisect run <test command>`, which uses the exit code to find the first bad commit automatically.
How do I undo a commit I already pushed?
Use `git revert <sha>` to add a new commit that reverses the change, then push. Avoid `git reset` or force-pushing on shared branches, since that rewrites history others depend on. If you need to recover a lost commit locally, `git reflog` shows where HEAD has been.
Related QAJobFit Guides
- CI/CD Interview Questions for QA Engineers
- Cloud Security QA Interview Questions for QA Engineers
- Jira Interview Questions for QA Engineers
- Accessibility Testing Interview Questions for QA Engineers
- AI Assisted Testing Interview Questions for QA Engineers
- AI QA Engineer Interview Questions for 2 Years Experience