Git Interview Questions & Answers for Testers
Git questions appear in almost every automation and SDET interview — usually alongside "how does your framework run in CI?". These are the 20 asked most, with answers you can say in under a minute. The command behavior shown (reset modes, reflog recovery, conflicts, stash) was checked in a real repository. For the full learning path, see The Complete Git Tutorial.
Git Basics (Q1–4)
Q1. What is Git?
A distributed version control system: it records every change to your files as commits, lets people work in parallel on branches, and gives every developer a full copy of the history. In automation, your framework code, test data and pipeline files all live in Git.
Learn more: Git Basics
Q2. Git vs GitHub?
Git is the version control tool that runs on your machine. GitHub is a hosting service for Git repositories that adds pull requests, code review, issues and Actions (CI). GitLab and Bitbucket are alternatives to GitHub; all of them use Git.
Q3. Local vs remote repository?
The local repository is the copy on your machine, where you commit. The remote (usually called origin) is the shared copy on GitHub or GitLab. You push commits to it and fetch/pull others' commits from it.
Q4. What does git init do?
Creates a new, empty repository in the current folder by adding a hidden .git directory. To start from an existing remote project, use git clone instead.
Core Commands (Q5–9)
Q5. git add vs git commit?
git add moves changes into the staging area — choosing what goes into the next commit. git commit saves the staged changes as a snapshot in the local history. Nothing reaches the remote until git push.
Working directory --git add--> Staging area --git commit--> Local repo --git push--> Remote
Learn more: Git Commands & Usage
Q6. git fetch vs git pull? ⭐
git fetch downloads new commits from the remote but doesn't change your working files — you can inspect them first (git log main..origin/main). git pull is fetch plus merge (or rebase) into your current branch. Fetch is the safe "what's new?"; pull updates your code.
Q7. What does git clone do?
Creates a local copy of a remote repository — all files, branches and history — and sets the remote up as origin. It's how a CI job gets your framework code before running mvn test.
Q8. git commit -m vs git commit --amend?
-m creates a new commit with a message. --amend replaces the last commit — to fix its message or add a forgotten file. It rewrites that commit, so only amend commits you haven't pushed (or you'll need a force push).
Q9. How do you view commit history?
git log # full history
git log --oneline # one line per commit
git log --oneline --graph --all # branches drawn as a graph
git log -p -- path/to/Test.java # changes to one file
git blame LoginPage.java # who last changed each line
Branching & Merging (Q10–14)
Q10. What is a branch?
A movable pointer to a commit — an independent line of work. Teams create a branch per feature or fix (feature/login-tests), then merge it back through a pull request.
git switch -c feature/login-tests # create and switch (older: git checkout -b)
git branch # list branches
Learn more: Branching & Merging
Q11. Merge vs rebase? ⭐
| Merge | Rebase | |
|---|---|---|
| What it does | Joins two branches with a merge commit | Replays your commits on top of another branch |
| History | Preserved exactly; can look busy | Linear and clean |
| Rewrites commits | No | Yes — new commit IDs |
| Safe on shared branches | Yes | No |
| Typical use | Merging a feature into main | Updating your own feature branch with the latest main |
Q12. What causes a merge conflict, and how do you resolve it?
Two branches changed the same lines of a file (or one edited a file the other deleted), so Git can't decide which to keep. It marks the file:
<<<<<<< HEAD
two
=======
one
>>>>>>> b1
Edit the file to the correct final content, remove the markers, then git add it and git commit (or git rebase --continue during a rebase). git merge --abort cancels and returns to the state before the merge. After resolving, run the affected tests before pushing.
Learn more: Git Errors & Troubleshooting
Q13. Fast-forward vs three-way merge?
Fast-forward: the target branch hasn't moved since you branched, so Git simply moves its pointer forward — no merge commit (Git reports "Fast-forward").
Three-way: both branches have new commits, so Git combines them using their common ancestor and creates a merge commit. git merge --no-ff forces a merge commit even when fast-forward is possible.
Q14. When should you avoid rebase?
On branches other people use (main, develop, a shared feature branch). Rebase rewrites commit IDs, so everyone else's copy diverges and they have to recover. Rule of thumb: rebase your own local work; merge shared work.
Learn more: Rebase, Cherry-Pick & Bisect
Undoing & Recovering (Q15–17)
Q15. git reset vs git revert? ⭐
git reset moves the branch pointer back, removing commits from the branch's history. git revert creates a new commit that undoes an earlier one, leaving history intact — so it's the safe choice for anything already pushed.
| Command | Commit removed? | Changes kept? | Verified result |
|---|---|---|---|
git reset --soft HEAD~1 |
Yes | Yes, staged | M f.txt (staged) |
git reset --mixed HEAD~1 (default) |
Yes | Yes, unstaged | M f.txt (unstaged) |
git reset --hard HEAD~1 |
Yes | No — discarded | Clean working directory |
git revert HEAD |
No | Undone by a new commit | Revert "…" commit added |
Learn more: Stash, Reset & Revert
Q16. What is git stash?
It shelves uncommitted changes and leaves a clean working directory, so you can switch branches (for an urgent fix, say) without committing half-done work.
git stash # save and clean up → stash@{0}: WIP on main: …
git stash list # see saved stashes
git stash pop # re-apply the latest and remove it from the list
git stash apply # re-apply but keep it in the list
git stash -u # include untracked (new) files
Q17. What is a detached HEAD? How do you recover a deleted branch or commit?
Detached HEAD means you've checked out a commit (or tag) directly rather than a branch — new commits there aren't on any branch. Keep them with git switch -c new-branch before switching away.
Recovery: git reflog lists every position HEAD has recently been at, including commits that no branch points to any more. Find the commit and put a branch back on it:
git reflog # e.g. 7fa2445 HEAD@{5}: commit: feat
git branch feature 7fa2445 # the deleted branch is back
git reset --hard HEAD@{1} # or undo an accidental reset --hard
Both were verified: a deleted branch and a hard-reset commit were recovered this way. Reflog is local and entries expire eventually, so recover soon.
Collaboration & Advanced Git (Q18–20)
Q18. What is a pull request?
A request to merge one branch into another, with a place for code review, discussion and automated checks. GitHub calls it a pull request (PR); GitLab calls it a merge request (MR). In automation teams, the PR usually triggers the test pipeline, and a failing suite blocks the merge.
Learn more: GitHub & GitLab: Pull Requests & CI/CD
Q19. What is cherry-pick?
git cherry-pick <commit> applies the changes from one specific commit onto your current branch as a new commit. Typical use: copying a hotfix from main into a release branch without merging everything else.
Q20. What is force push, and when is it safe?
git push --force overwrites the remote branch with your local history, discarding remote commits you don't have. It's only reasonable on your own branch after rewriting it (amend, rebase). Prefer git push --force-with-lease, which refuses if someone else has pushed in the meantime — and never force-push to main.
Bonus: Scenario Questions
- "You committed to main instead of a feature branch." Create the branch from the current commit (
git branch feature), then reset main back (git reset --hard origin/main) — before pushing. - "You pushed a bad commit." Use
git revert, not reset, so nobody else's history breaks. - "You committed a password." Remove it, but also rotate the credential — it's in the history and may already be copied.
- "Tests pass locally but fail in CI after a merge." Pull the merged main, run the suite locally, and check the merge didn't combine incompatible changes.
More: Git Real-Time Scenarios. Practice answering under time pressure in the Git Interview Simulator.
From the Interview Room
In my automation roles I maintained test scripts that several people reviewed and extended — POM classes, the business library and data files all changing at once. That's exactly the situation version control is built for: every change reviewed, traceable and easy to undo. On Canolog, the many forms and screens across sales, inventory, finance and service are where keeping page details in POM classes and reusable steps in a business library paid off. Be ready to explain merge versus rebase and how you'd resolve a conflict.
📚 Official documentation: Git documentation
FAQs
Which Git commands should a tester know?
clone, status, add, commit, push, fetch, pull, switch/checkout, branch, merge, log, stash, reset, revert — and how to resolve a conflict.
What branching strategy do teams use?
Commonly feature branches merged into main through pull requests, sometimes with release branches (Git Flow) or very short-lived branches (trunk-based development).
Where do test automation files go in Git?
Framework code, test data, config templates and pipeline files are committed; build output, reports, screenshots, logs and secrets are excluded with .gitignore.
How does Git connect to Jenkins?
The Jenkins job or pipeline clones the repository; a webhook triggers a build on every push or pull request. See The Complete Jenkins Tutorial.
What is .gitignore?
A file listing paths Git should ignore — for example target/, test-output/, *.log and local config with credentials.
Next Steps
- The Complete Git Tutorial
- Git Commands Cheat Sheet
- Jenkins Interview Questions
- The Complete SDET Interview Guide