Git Junior interview questions and answers

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

Take this quiz
  1. 1.What makes Git a distributed version control system?
  2. 2.What are the three main areas a file moves through in Git?
  3. 3.What does git add file.js do?
  4. 4.What does a Git commit store?
  5. 5.What identifies a commit in Git?
  6. 6.Which command shows modified, staged and untracked files?
  7. 7.What does plain git diff show?
  8. 8.How do you see what is staged for the next commit?
  9. 9.You added .env to .gitignore, but Git still tracks changes to it. Why?
  10. 10.What does git rm --cached file do?
  11. 11.Which .gitignore line ignores every node_modules folder in the project?
  12. 12.Why doesn't Git track an empty directory?
  13. 13.What does git clone <url> do?
  14. 14.What is origin?
  15. 15.What is the difference between git fetch and git pull?
  16. 16.git push is rejected with "non-fast-forward". What does it mean?
  17. 17.What is a branch in Git?
  18. 18.What is HEAD?
  19. 19.How do you create a branch and switch to it in one command?
  20. 20.What is a fast-forward merge?
  21. 21.When does Git create a merge commit?
  22. 22.What do the markers <<<<<<<, ======= and >>>>>>> in a file mean?
  23. 23.How do you abort a merge that has conflicts and go back to the previous state?
  24. 24.How do you delete a local branch that has been merged?
  25. 25.How do you delete a branch on the remote?
  26. 26.What is origin/main?
  27. 27.How do you fix the message of the last commit before pushing?
  28. 28.How do you discard uncommitted changes to one file?
  29. 29.How do you unstage a file but keep its changes?
  30. 30.What does git revert <commit> do?
  31. 31.When is git reset risky and git revert preferable?
  32. 32.What does git stash do?
  33. 33.What is the difference between git stash pop and git stash apply?
  34. 34.What is a tag in Git usually used for?
  35. 35.Are tags pushed by a plain git push?
  36. 36.Which command shows a compact one-line history?
  37. 37.How do you find who last changed each line of a file?
  38. 38.What does git commit -a -m "msg" do?
  39. 39.Why should you set user.name and user.email in Git?
  40. 40.What does git init do?
  41. 41.What is in the .git folder?
  42. 42.What is a "detached HEAD"?
  43. 43.What is a pull request (merge request)?
  44. 44.What is a fork?
  45. 45.What makes a good commit message?
  46. 46.What is the main idea of small, focused commits?
  47. 47.You accidentally committed an API key and pushed it. What must you do first?
  48. 48.What does git log main..feature show?
  49. 49.Which command shows the changes introduced by a single commit?
  50. 50.What does HEAD~1 refer to?
  51. 51.What does git reset --soft HEAD~1 do?
  52. 52.What is the danger of git reset --hard?
  53. 53.Why is node_modules usually not committed?
  54. 54.What is git switch for compared with git checkout?
  55. 55.What does git branch -a list?
  56. 56.How do you set the upstream branch when pushing a new branch for the first time?
  57. 57.What does git clean -n do?
  58. 58.Why can git pull create unexpected merge commits like "Merge branch 'main' of ..."?
  59. 59.What is a .gitattributes file used for?
  60. 60.Why do Windows and macOS users sometimes see every line of a file as changed?
  61. 61.Which file is a bad idea to commit to a Git repository?
  62. 62.What does git mv old.js new.js do?
  63. 63.What does git log -p file.js show?
  64. 64.What does "Your branch is ahead of 'origin/main' by 2 commits" mean?
  65. 65.Why should you pull or fetch before starting work on a shared branch?
  66. 66.What does git diff main feature compare?
  67. 67.What is a lockfile conflict in package-lock.json usually best resolved with?
  68. 68.What does git checkout v1.0 (a tag) leave you in?
  69. 69.What is semantic versioning (MAJOR.MINOR.PATCH)?
  70. 70.Which statement about deleting a branch is true?
  71. 71.What does git commit --amend --no-edit do?
  72. 72.What is the purpose of a README.md in the repository root?
  73. 73.What does git log --author="Ann" do?
  74. 74.What is the difference between tracked and untracked files?
  75. 75.Two people edited different functions in the same file. What happens when their branches merge?