Git interview questions

// 40 QUESTIONS · UPDATED MAY 2026

Git interview questions for QA engineers and SDETs. Branching strategies, merge vs rebase, conflict resolution, force-push safety, common workflows (Gitflow, trunk-based), interactive rebase, cherry-pick, and the day-to-day Git you need on a QA team.

Level

Showing 40 of 40 questions

  1. Explain the difference between git merge and git rebase.Junior

    git merge joins two branches by creating a merge commit with two parents, preserving full branching history. git rebase re-applies your c…

  2. When is force-push safe and when is it dangerous?Mid

    Force-push is safe on a private branch only you have checked out, after a local rebase or reword. It's dangerous on any shared branch — i…

  3. Walk through resolving a complex merge conflict in a Java test class.Senior

    A conflict in a Java test class typically happens when two branches modified the same method or class-level setup. Resolve it by reading…

  4. What's the difference between `git fetch` and `git pull`?Junior

    git fetch downloads new commits and branch refs from the remote but doesn't change your working directory or current branch. git pull is…

  5. What does `git add` actually do?Junior

    git add copies the current state of a file from the working directory into the staging area (the index). It doesn't write anything perman…

  6. Explain the difference between the working directory, staging area, and commit.Junior

    The working directory contains your actual files as you edit them. The staging area (index) holds the snapshot of changes selected for th…

  7. How do you check the status of your repository and the current branch?Junior

    git status shows the current branch, staged changes, unstaged changes, and untracked files in one view. git branch lists local branches (…

  8. How do you view the commit history? How do you make it readable?Junior

    git log --oneline --graph --decorate --all gives a compact one-line-per-commit graph with branch labels. Use --author, --since, --grep, o…

  9. What is HEAD in Git?Junior

    HEAD is a file in .git/HEAD that points to the current branch ref, which in turn points to the latest commit on that branch. It moves for…

  10. How do you create a new branch and switch to it?Junior

    git switch -c feature/my-branch creates and switches in one command (modern syntax). To base it on a specific point: git switch -c featur…

  11. What does `git diff` show by default?Junior

    git diff with no arguments shows unstaged changes — the difference between the working directory and the staging area. git diff --staged…

  12. How do you discard local uncommitted changes?Junior

    For unstaged files: git restore <file> (modern) discards working-directory changes. For staged files: git restore --staged <file> to unst…

  13. What does `.gitignore` do, and where should it live?Junior

    `.gitignore` lists file patterns that Git should not track or show in git status. It should live at the repository root for project-wide…

  14. How do you see who last changed a specific line in a file?Junior

    git blame <file> annotates every line with the commit SHA, author name, and date of the last change. git blame -L 42,55 <file> limits the…

  15. What is the difference between `git revert` and `git reset`, and when should you use each?Mid

    `git revert` creates a new commit that undoes a previous commit — safe for shared history. `git reset` moves HEAD (and optionally the ind…

  16. Explain the three modes of `git reset` — `--soft`, `--mixed`, and `--hard` — with concrete use cases for each.Mid

    `--soft` moves HEAD only (staged diff preserved), `--mixed` moves HEAD + clears the index (changes land unstaged), `--hard` moves HEAD +…

  17. How do you fix a commit message or add a forgotten file to the most recent commit without creating a new commit?Mid

    `git commit --amend` rewrites the last commit: `--amend -m 'new msg'` fixes the message; staging forgotten files first then `--amend --no…

  18. How does `git stash` work, and what are the common pitfalls of using it in a team QA workflow?Mid

    `git stash` saves dirty working tree and index to a stack, letting you switch context cleanly. Pitfalls: stashes are local (not pushed),…

  19. When would you use `git cherry-pick`, and how do you cherry-pick a range of commits?Mid

    `git cherry-pick <sha>` applies a single commit's diff onto HEAD without merging the whole branch. Use it to backport a hotfix to a relea…

  20. How do you use interactive rebase to clean up your local commit history before raising a PR?Mid

    `git rebase -i HEAD~N` opens an editor listing the last N commits. You can reorder, squash (combine), fixup (squash + discard msg), rewor…

  21. Why do many teams configure `git pull --rebase` as the default, and how do you set this globally?Mid

    `git pull --rebase` replays your local commits on top of the updated remote tip instead of creating a merge commit, keeping history linea…

  22. How does `--force-with-lease` protect against overwriting a colleague's work, and when can it still fail?Mid

    `--force-with-lease` compares your local remote-tracking ref (origin/branch) against the actual remote tip before pushing. If they differ…

  23. What is `.gitattributes` and how do you use it to prevent line-ending and diff issues in a cross-platform QA team?Mid

    `.gitattributes` declares per-path attributes that control line endings (`text eol=lf`), diff drivers, merge strategies, and binary file…

  24. How does `git bisect` work, and how would you use it to find which commit broke an API test?Mid

    `git bisect` performs a binary search through commit history: you mark the current commit as 'bad' and an older known-good commit as 'goo…

  25. What is the difference between a fast-forward merge and a no-fast-forward (--no-ff) merge, and which should a QA team prefer?Mid

    Fast-forward simply moves the branch pointer forward (no merge commit, linear history). `--no-ff` always creates a merge commit, preservi…

  26. How do you manage multiple remotes in Git, and when would a QA engineer need more than one remote?Mid

    `git remote add <name> <url>` registers a remote. Multiple remotes are used when working with forks (origin = your fork, upstream = canon…

  27. How do you rename a local and remote branch in Git without breaking existing pull requests?Mid

    Rename locally with `git branch -m old new`, delete the old remote branch, push the new one. Open PRs targeting the old branch name must…

  28. A bad commit was merged to `main` and CI is broken. What are your options for undoing it, and which is safest?Mid

    Safest: `git revert <sha>` (or `git revert -m 1 <merge-sha>`) to create an undo commit — no history rewrite, safe for shared branches. Nu…

  29. Compare Gitflow and trunk-based development — what are the QA testing implications of each?Mid

    Gitflow uses long-lived feature/develop/release branches — QA tests each branch independently, enabling thorough gating but risking integ…

  30. Your local Git repository is reporting corrupted objects or a detached HEAD you can't escape. How do you diagnose and recover?Mid

    `git fsck --full` finds corrupted or dangling objects. For detached HEAD, `git switch -` returns to the previous branch. For corrupt obje…

  31. Design a Git branching and tagging strategy for a 5-team QA organisation that needs to test features independently and also run full regression across all features before release.Senior

    Use trunk-based dev with short-lived feature branches per team, a shared `integration` branch for cross-team regression, and immutable re…

  32. Describe the Git object model — blobs, trees, commits, and tags — and explain why this model makes Git operations fast and safe.Senior

    Git stores everything as content-addressed objects (SHA-1/SHA-256). Blobs = file content, trees = directory snapshots, commits = tree + p…

  33. A teammate accidentally force-pushed to `main` and lost 3 commits that were never backed up. How do you recover them?Senior

    Check the teammate's local `git reflog` — the lost commits are still in their `.git/objects` for 30 days. Copy the SHAs, push the commits…

  34. Explain `git reflog` — what it records, for how long, and walk through a scenario where it saves a QA engineer's work.Senior

    `git reflog` records every position HEAD (and every branch ref) has been at, even after resets, rebases, and branch deletes. Entries are…

  35. A QA repo is growing uncontrollably because large binary test fixtures (video recordings, DB dumps) are committed directly. How do you solve this?Senior

    Replace binaries with Git LFS pointers (`git lfs track '*.mp4'`), which stores the actual blobs in an external store and keeps the repo l…

  36. How would you implement a pre-commit hook that blocks QA engineers from committing test files containing skipped tests or hard-coded credentials?Senior

    Write a `.git/hooks/pre-commit` shell script that greps staged files for `@Disabled`/`xit`/`xtest` and common credential patterns. Exit n…

  37. Your organisation is migrating from SVN to Git. What are the key steps and the main risks for the QA test repository?Senior

    Use `git svn clone` or `svn2git` to import history with author mapping. Key risks: SVN externals become submodules (painful), binary test…

  38. A QA engineer discovers that an API key was committed to the test repository 6 months ago and is still in Git history. What is your remediation plan?Senior

    Immediate: revoke the key. Then rewrite history with `git filter-repo --path-glob '*.env' --invert-paths` or a text replacement filter. F…

  39. As a QA lead, how would you configure branch protection rules for `main` and `release/*` branches to enforce quality gates without slowing down the team?Lead

    Protect `main` with: required PR reviews (1-2), required CI status checks (unit + integration), signed commits, and block force-pushes. F…

  40. Your team has been using 'commit everything directly to main' for 2 years. How do you lead the transition to a PR-based workflow with branch protection, and what are the biggest risks?Lead

    Introduce the new workflow incrementally: start with a protected `main` that allows direct pushes to admins only, run short-lived branche…