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. How do you resolve a merge conflict in Git?

    Run git status to see the conflicted files, open each one and find the markers <<<<<<<, ======= and >>>>>>>. Edit the code to the correct final version, delete the markers, then git add the file and run git commit (or git rebase --continue during a rebase). Test before you push.

    BeginnerIn-depth3 min read
  2. 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
  3. How do you cancel a merge that went wrong?

    Run git merge --abort. It restores your branch and working tree to the state before the merge started. It works while the merge is still unresolved and uncommitted.

    BeginnerQuick answer1 min read
  4. What are the three ways to merge a pull request on GitHub?

    Create a merge commit keeps all commits plus a merge commit. Squash and merge combines them into one commit. Rebase and merge replays the commits onto main without a merge commit, giving linear history.

    BeginnerQuick answer1 min read
  5. What do the <<<<<<<, ======= and >>>>>>> markers in a file mean?

    They are Git's conflict markers. The part between <<<<<<< and ======= is your current branch's version, and the part between ======= and >>>>>>> is the incoming version. You edit the file to the final text and delete all three marker lines.

    BeginnerQuick answer1 min read
  6. What is a fast-forward merge, and when does Git use it?

    A fast-forward merge happens when the target branch has no new commits of its own, so Git just moves its pointer forward to the other branch's tip. No merge commit is created and history stays a straight line.

    BeginnerQuick answer1 min read
  7. What is a merge commit, and how is it different from a normal commit?

    A merge commit has two (or more) parents instead of one. It records the point where two lines of history were joined, and holds the combined result of both branches.

    BeginnerQuick answer1 min read
  8. How does a three-way merge work in Git?

    Git compares three snapshots: the two branch tips and their common ancestor. Changes made on only one side are taken automatically; if both sides changed the same lines differently, Git reports a conflict.

    IntermediateQuick answer1 min read
  9. What does git merge --squash do?

    It combines all changes from a branch into the working tree and staging area as one set of changes, without creating a merge commit. You then commit once, so the branch's many commits become a single commit on main.

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