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