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 big should a commit be?

    One logical change that builds and passes tests on its own. Small, focused commits are easier to review, revert, cherry-pick and bisect than a giant commit mixing several unrelated things.

    BeginnerQuick answer1 min read
  2. How do you change the message or contents of your last commit?

    Use git commit --amend. It replaces the last commit with a new one, letting you edit the message and include newly staged changes. Because it rewrites history, avoid it on commits you have already pushed and shared.

    BeginnerQuick answer1 min read
  3. How do you tag a commit that is not the latest one?

    Give the commit hash after the tag name, for example git tag -a v1.0 3f9c2ab -m 'Release 1.0'. Without a hash, Git tags the current HEAD.

    BeginnerQuick answer1 min read
  4. How do you undo the last commit but keep your changes?

    Run git reset --soft HEAD~1 to keep the changes staged, or git reset HEAD~1 to keep them unstaged. The commit disappears from the branch while your work stays in the files.

    BeginnerQuick answer1 min read
  5. 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
  6. What is a commit hash, and why is it such a long string?

    A commit hash is a SHA-1 fingerprint of the commit's contents, author, message and parent. It uniquely identifies the commit and changes if anything inside it changes. You can usually use just the first 7 characters.

    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. 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