Git Senior interview questions and answers

76 questions for a Git (Senior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.Which four object types make up Git's object database?
  2. 2.Why does renaming a file not duplicate its content in Git's storage?
  3. 3.What is a ref in Git internally?
  4. 4.What does git gc do?
  5. 5.How do packfiles keep repositories small?
  6. 6.Why can a commit that's no longer on any branch still be recovered?
  7. 7.What is Git moving to as an alternative to SHA-1, and why?
  8. 8.What does a three-way merge compare?
  9. 9.What is ort?
  10. 10.What is the difference between -s ours and -X ours in a merge?
  11. 11.What is an octopus merge?
  12. 12.How do you remove a leaked secret from a repository's whole history?
  13. 13.Why is git filter-branch discouraged today?
  14. 14.A teammate force-pushed and your main diverged. What is the safest recovery?
  15. 15.What does a partial clone with --filter=blob:none do?
  16. 16.Why does git status get slow in very large repositories, and what helps?
  17. 17.What is a refspec, like +refs/heads/*:refs/remotes/origin/*?
  18. 18.Submodule vs subtree: what's the key trade-off?
  19. 19.Why can a revert of a merge cause trouble when the branch is merged again later?
  20. 20.How does git cherry or patch-id detection help after cherry-picking?
  21. 21.What does git rebase --update-refs help with in stacked branches?
  22. 22.What problem does a merge queue solve?
  23. 23.Why should every commit on main build and pass tests, not just the PR's final state?
  24. 24.How do you handle untestable commits during git bisect?
  25. 25.What makes git bisect run ./test.sh work?
  26. 26.Why might a signed commit still not prove the code is safe?
  27. 27.What can a server-side pre-receive hook do that client hooks can't?
  28. 28.What does git notes let you attach?
  29. 29.Why can a branch named feature block creating feature/login?
  30. 30.What is the index (staging area) technically?
  31. 31.During a conflict, what are index stages 1, 2 and 3?
  32. 32.How do you get exactly "their" version of a conflicted file during a merge?
  33. 33.During git rebase main, what do "ours" and "theirs" refer to?
  34. 34.What does git replace do?
  35. 35.What does Git LFS file locking address?
  36. 36.Why are huge files committed by mistake a long-term problem even after deletion?
  37. 37.What does Git protocol v2 improve?
  38. 38.What does git clone --mirror produce?
  39. 39.What is the point of the commit-graph file?
  40. 40.Why are stacked pull requests used?
  41. 41.How do Conventional Commits enable automated releases?
  42. 42.What does git log --follow struggle with?
  43. 43.Why might git blame show the wrong author after a file was split into two?
  44. 44.What is a criss-cross merge history?
  45. 45.How do you produce a release whose source can be reproduced exactly?
  46. 46.Why do some teams forbid merge commits from main into feature branches?
  47. 47.What happens to open pull requests when you rewrite main's history?
  48. 48.What is git bundle useful for?
  49. 49.Why is git push origin main:production interesting?
  50. 50.What risk comes with git config --global url."git@github.com:".insteadOf?
  51. 51.How are credentials best handled for HTTPS remotes?
  52. 52.What does git maintenance start set up?
  53. 53.Why is "merge commit" vs "squash" a team decision rather than a personal one?
  54. 54.What is a symbolic ref?
  55. 55.How can you check that a repository's objects are not corrupted?
  56. 56.Why is git push --force to a shared branch dangerous even with backups on CI?
  57. 57.What is the trade-off of a monorepo with Git compared with many repositories?
  58. 58.Why do rebased commits keep their original author date but change the committer date?
  59. 59.What does git log --cherry-pick --left-right A...B reveal?
  60. 60.How do you prevent a huge package-lock.json diff from drowning the real change in review?
  61. 61.What does a custom merge driver in .gitattributes allow?
  62. 62.Why is rewriting history in a fork-based open-source project especially disruptive?
  63. 63.What is the main reason Git can create branches in constant time?
  64. 64.How does git rerere interact with a long rebase you abort and redo?
  65. 65.Why might CI on a shallow clone compute the wrong set of changed files?
  66. 66.What is a "dangling commit"?
  67. 67.Why should you avoid putting secrets in commit messages, branch names or tags?
  68. 68.What does git switch --orphan docs create?
  69. 69.Why can two developers see different results from the same git log command?
  70. 70.When is git merge --no-ff useful even when a fast-forward is possible?
  71. 71.What does git range-diff give a reviewer after a force-pushed PR update?
  72. 72.Why is git stash risky as long-term storage?
  73. 73.What does git log --merges --first-parent list on main?
  74. 74.What is the cost of a very large number of refs (for example millions of PR refs)?
  75. 75.Why is git worktree safer than cloning the repo twice for parallel work?
  76. 76.What happens to commit hashes when you rebase onto the same base without changes?