Git Middle interview questions and answers

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

Take this quiz
  1. 1.What does git rebase main do on a feature branch?
  2. 2.What is the "golden rule" of rebasing?
  3. 3.Merge vs rebase for integrating main into a feature branch: what's the trade-off?
  4. 4.During a rebase you hit a conflict. What's the usual sequence?
  5. 5.What can git rebase -i HEAD~4 do?
  6. 6.What is the difference between squash and fixup in interactive rebase?
  7. 7.What does git cherry-pick <hash> do?
  8. 8.You ran git reset --hard and lost a commit. How can you get it back?
  9. 9.What is the default mode of git reset <commit>?
  10. 10.Why prefer git push --force-with-lease over --force?
  11. 11.How do you undo a merge commit that was already pushed to main?
  12. 12.What does a squash merge of a pull request do?
  13. 13.What does git bisect help you find?
  14. 14.What is a Git hook?
  15. 15.What is a pre-commit hook commonly used for?
  16. 16.What does Conventional Commits standardize?
  17. 17.What is trunk-based development?
  18. 18.How does Git Flow differ from GitHub Flow?
  19. 19.What do protected branches on GitHub or GitLab typically enforce?
  20. 20.What is a CODEOWNERS file?
  21. 21.What does git add -p let you do?
  22. 22.What is ORIG_HEAD?
  23. 23.What does the three-dot range git log main...feature show?
  24. 24.What is the merge base of two branches?
  25. 25.Annotated vs lightweight tags: what's the difference?
  26. 26.Why sign commits or tags with GPG or SSH keys?
  27. 27.What is a Git submodule?
  28. 28.What problem does git worktree solve?
  29. 29.What does a shallow clone (git clone --depth 1) give you?
  30. 30.Why use Git LFS for large binary files?
  31. 31.What does git log -S "apiKey" find?
  32. 32.How do you keep your fork in sync with the original repository?
  33. 33.What does git fetch --prune do?
  34. 34.What does pull.ff = only in Git config do?
  35. 35.What does git rebase --onto main old-base feature do?
  36. 36.What does .git-blame-ignore-revs help with?
  37. 37.What does git stash -u add compared with plain git stash?
  38. 38.How do you create a branch from a stash?
  39. 39.What does git rerere do?
  40. 40.Why can a rebase with many commits be more painful than a merge?
  41. 41.What does git describe output, like v1.4.0-12-g3f2a9c1?
  42. 42.What does git shortlog -sn show?
  43. 43.What happens to your commits when you squash-merge a PR and keep working on the same branch?
  44. 44.What is git cherry-pick -x useful for?
  45. 45.How do you see which branches contain a given commit?
  46. 46.Why might renaming File.js to file.js cause trouble on macOS or Windows?
  47. 47.What is core.fileMode about?
  48. 48.What does git range-diff compare?
  49. 49.What does git commit --fixup=<hash> prepare?
  50. 50.Why do many teams require linear history on main?
  51. 51.What does git log --graph --oneline --all help you see?
  52. 52.You committed to main by mistake instead of a feature branch (not pushed). How do you fix it?
  53. 53.What does git clean -fdx remove?
  54. 54.Why is a long-lived feature branch risky?
  55. 55.What does git diff --stat show?
  56. 56.What does git restore --source=HEAD~2 file.js do?
  57. 57.What is a release branch used for in Git Flow?
  58. 58.How should a hotfix for production be handled with release branches?
  59. 59.What does git grep "TODO" search?
  60. 60.What does sparse checkout let you do in a big monorepo?
  61. 61.What does git reset --merge or git merge --abort protect that reset --hard doesn't?
  62. 62.Why are generated files (build output, minified bundles) usually ignored?
  63. 63.What happens with git commit --amend on a commit that's already pushed?
  64. 64.What is the safest way to bring the latest main into a branch that others also push to?
  65. 65.What does git log --first-parent main show?
  66. 66.What does git switch - do?
  67. 67.Where should you resolve a package.json version conflict between two feature branches?
  68. 68.What does git revert HEAD~3..HEAD do?
  69. 69.How can you edit an older commit's content (not just its message) before pushing?
  70. 70.What is the risk of git add . before every commit?
  71. 71.What does git log --since="2 weeks ago" -- src/api show?
  72. 72.What is git push --atomic for?
  73. 73.Why do monorepos often use CODEOWNERS and path-based CI?
  74. 74.What is the downside of rebase-and-merge on a hosting platform?
  75. 75.What does git merge --squash feature do locally?