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.What does
git rebase maindo on a feature branch? - 2.What is the "golden rule" of rebasing?
- 3.Merge vs rebase for integrating
maininto a feature branch: what's the trade-off? - 4.During a rebase you hit a conflict. What's the usual sequence?
- 5.What can
git rebase -i HEAD~4do? - 6.What is the difference between
squashandfixupin interactive rebase? - 7.What does
git cherry-pick <hash>do? - 8.You ran
git reset --hardand lost a commit. How can you get it back? - 9.What is the default mode of
git reset <commit>? - 10.Why prefer
git push --force-with-leaseover--force? - 11.How do you undo a merge commit that was already pushed to
main? - 12.What does a squash merge of a pull request do?
- 13.What does
git bisecthelp you find? - 14.What is a Git hook?
- 15.What is a
pre-commithook commonly used for? - 16.What does Conventional Commits standardize?
- 17.What is trunk-based development?
- 18.How does Git Flow differ from GitHub Flow?
- 19.What do protected branches on GitHub or GitLab typically enforce?
- 20.What is a
CODEOWNERSfile? - 21.What does
git add -plet you do? - 22.What is
ORIG_HEAD? - 23.What does the three-dot range
git log main...featureshow? - 24.What is the merge base of two branches?
- 25.Annotated vs lightweight tags: what's the difference?
- 26.Why sign commits or tags with GPG or SSH keys?
- 27.What is a Git submodule?
- 28.What problem does
git worktreesolve? - 29.What does a shallow clone (
git clone --depth 1) give you? - 30.Why use Git LFS for large binary files?
- 31.What does
git log -S "apiKey"find? - 32.How do you keep your fork in sync with the original repository?
- 33.What does
git fetch --prunedo? - 34.What does
pull.ff = onlyin Git config do? - 35.What does
git rebase --onto main old-base featuredo? - 36.What does
.git-blame-ignore-revshelp with? - 37.What does
git stash -uadd compared with plaingit stash? - 38.How do you create a branch from a stash?
- 39.What does
git rereredo? - 40.Why can a rebase with many commits be more painful than a merge?
- 41.What does
git describeoutput, likev1.4.0-12-g3f2a9c1? - 42.What does
git shortlog -snshow? - 43.What happens to your commits when you squash-merge a PR and keep working on the same branch?
- 44.What is
git cherry-pick -xuseful for? - 45.How do you see which branches contain a given commit?
- 46.Why might renaming
File.jstofile.jscause trouble on macOS or Windows? - 47.What is
core.fileModeabout? - 48.What does
git range-diffcompare? - 49.What does
git commit --fixup=<hash>prepare? - 50.Why do many teams require linear history on
main? - 51.What does
git log --graph --oneline --allhelp you see? - 52.You committed to
mainby mistake instead of a feature branch (not pushed). How do you fix it? - 53.What does
git clean -fdxremove? - 54.Why is a long-lived feature branch risky?
- 55.What does
git diff --statshow? - 56.What does
git restore --source=HEAD~2 file.jsdo? - 57.What is a release branch used for in Git Flow?
- 58.How should a hotfix for production be handled with release branches?
- 59.What does
git grep "TODO"search? - 60.What does sparse checkout let you do in a big monorepo?
- 61.What does
git reset --mergeorgit merge --abortprotect thatreset --harddoesn't? - 62.Why are generated files (build output, minified bundles) usually ignored?
- 63.What happens with
git commit --amendon a commit that's already pushed? - 64.What is the safest way to bring the latest
maininto a branch that others also push to? - 65.What does
git log --first-parent mainshow? - 66.What does
git switch -do? - 67.Where should you resolve a
package.jsonversion conflict between two feature branches? - 68.What does
git revert HEAD~3..HEADdo? - 69.How can you edit an older commit's content (not just its message) before pushing?
- 70.What is the risk of
git add .before every commit? - 71.What does
git log --since="2 weeks ago" -- src/apishow? - 72.What is
git push --atomicfor? - 73.Why do monorepos often use
CODEOWNERSand path-based CI? - 74.What is the downside of rebase-and-merge on a hosting platform?
- 75.What does
git merge --squash featuredo locally?