Interview Q&A / Git & GitHub
Git & GitHub interview questions
Branching, merge vs rebase, resolving conflicts and pull requests, the way teams actually work.
Prefer rapid revision? Practise Git & GitHub short interview answers →
- Why is a submodule in detached HEAD state, and is that a problem?
The parent pins an exact commit, so Git checks the submodule out at that commit, not on a branch. It is normal. To edit the submodule, check out a branch inside it first, or commits can get lost.
IntermediateQuick answer1 min read - How can you automate git bisect with a script?
Use git bisect run with a command that exits 0 for good and non-zero (except 125) for bad. Git then runs it at each step and finds the culprit commit without manual answers.
AdvancedQuick answer1 min read - How do you cherry-pick a merge commit?
Add -m 1 (or -m 2) to say which parent is the mainline, because a merge commit has two parents and Git cannot know which side's diff to copy.
AdvancedQuick answer1 min read - How do you remove a submodule properly?
Run git submodule deinit -f path, then git rm -f path, and delete the leftover .git/modules/path folder. Commit the change. Just deleting the folder leaves stale configuration behind.
AdvancedQuick answer1 min read - What does git rebase --onto do?
git rebase --onto newbase oldbase branch moves only the commits after oldbase onto a different base. It lets you transplant part of a branch, for example when a branch was started from the wrong parent.
AdvancedQuick answer1 min read - What does git revert -n (--no-commit) do?
It applies the reverse of a commit to your working tree and index without committing. This lets you revert several commits and record them together as a single commit.
AdvancedQuick answer1 min read - What is git rerere?
rerere means reuse recorded resolution. When enabled, Git remembers how you resolved a conflict and applies the same fix automatically if the same conflict appears again, such as during repeated rebases.
AdvancedQuick answer1 min read