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 is the difference between git merge and git rebase?

    Both bring changes from one branch into another. Merge joins the two histories with a new merge commit and keeps everything as it happened. Rebase replays your commits on top of the other branch, giving a straight, linear history but rewriting commit IDs. Never rebase commits that others have already pulled.

    IntermediateIn-depth3 min read
  2. How do you fix the message of a commit that is not the latest?

    Run git rebase -i, mark that commit as reword, save, and edit the message. Only do this for commits not yet shared, since every commit after it also gets a new hash.

    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. What does git pull --rebase do, and why do many teams prefer it?

    It fetches remote changes and replays your local commits on top of them instead of creating a merge commit. The result is a linear history without noisy 'Merge branch main' commits.

    IntermediateQuick answer1 min read
  5. What happens when a conflict occurs during a rebase, and how do you continue?

    Rebase stops at the commit that conflicts. You fix the files, git add them, and run git rebase --continue. You can skip that commit with --skip or give up entirely with --abort.

    IntermediateQuick answer1 min read
  6. What is git rebase -i, and what can you do with it?

    Interactive rebase opens a list of your recent commits so you can reorder, reword, squash, edit, or drop them before they are replayed. It is the standard way to tidy a messy branch before opening a pull request.

    IntermediateQuick answer1 min read
  7. What is the difference between squash and fixup in an interactive rebase?

    Both merge a commit into the one above it. squash lets you combine and edit the two commit messages, while fixup silently discards the second message and keeps the first as it is.

    IntermediateQuick answer1 min read