Interview Q&A / Git & GitHub

INTERVIEW Q&A · 97 QUESTIONS

Git & GitHub interview questions

Branching, merge vs rebase, resolving conflicts and pull requests, the way teams actually work.

  1. What does git cherry-pick do?

    cherry-pick copies the changes of one chosen commit onto your current branch as a new commit. It lets you take a single fix without merging the whole branch it lives on.

    BeginnerQuick answer1 min read
  2. How do you cherry-pick a range of commits, and what if there is a conflict?

    Use git cherry-pick A^..B to copy commits from A through B. On conflict, fix the files, git add them and run git cherry-pick --continue, or use --abort to cancel.

    IntermediateQuick answer1 min read
  3. Is cherry-pick the same as rebase for moving one commit?

    They are close, but cherry-pick copies a commit and leaves the original where it is, while rebase moves a whole sequence of your branch's commits and abandons the originals.

    IntermediateQuick answer1 min read
  4. When is cherry-pick a bad idea?

    Overusing it creates duplicate commits with different hashes, which later cause confusing conflicts when the branches are merged. Prefer merging or rebasing when you want the whole branch.

    IntermediateQuick answer1 min read
  5. 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