Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Git

    Interview Questions

    Real interview questions on Git, answered the way you would say them out loud.

    Extra: Interview prep4 min read

    Interview questions

    What's the difference between merge and rebase? When would you use each?

    How I'd answer: "Both integrate changes from one branch into another. Merge creates a merge commit with two parents; it keeps the true history, including the fact that work happened in parallel, and never rewrites existing commits. Rebase replays my commits on top of the target branch as new commits, giving a linear history that's easier to read and bisect — but it rewrites those commits' hashes.

    So I rebase my own local, unshared work — for example git pull --rebase before pushing, or tidying commits with interactive rebase before a PR. I never rebase commits others already have. For integrating a finished feature into main, teams usually merge or squash-merge through the PR."

    Combines: Ch 5, 6, 8.

    You pushed a commit to main that broke production. How do you undo it?

    How I'd answer: "I'd use git revert <hash>, which creates a new commit that applies the exact opposite changes, then push it through the normal pipeline so production gets the fix. I wouldn't reset and force-push, because main is shared: that rewrites history that teammates and CI already have, and can delete others' commits. After the revert, I'd reproduce the bug on a branch, fix it properly with a test, and re-land it."

    Combines: Ch 7, 9.

    How would you find which commit introduced a bug?

    How I'd answer: "If I have a known good version, like the last release tag, I'd use git bisect: mark the current commit bad and the tag good, and Git checks out the midpoint each time so I can test it — it's a binary search, so 1,000 commits takes about 10 steps. If I can write a script that exits non-zero when the bug appears, git bisect run automates the whole thing. If I already suspect a specific line, git blame shows the commit and author that last changed it, and git log -p on the file shows its full history."

    Combines: Ch 3, 11.

    A teammate committed an AWS key and pushed it. What do you do?

    How I'd answer: "First, revoke the key in AWS immediately and issue a new one — assume it's compromised, because bots scan public repos within minutes. Then check AWS for any activity from the leaked key. Deleting the file in a new commit isn't enough, since it's still in history, so I'd purge it from history with git filter-repo, force-push, and have everyone re-clone. Finally, prevent a repeat: make sure .env and key files are in .gitignore, and add secret scanning in pre-commit hooks and CI."

    Combines: Ch 3, 7, 10.

    What actually happens in Git when you create a branch and commit?

    How I'd answer: "A branch is just a file in .git/refs/heads containing a commit hash, so creating one is instant. HEAD points to the current branch. When I commit, Git stores each staged file as a blob, builds tree objects for the directories, and writes a commit object pointing to the top tree and to the parent commit, with author and message. Each object is named by the hash of its contents. Finally the current branch's file is updated to the new commit's hash. Because each commit includes its parent's hash, the whole history is tamper-evident."

    Combines: Ch 2, 3, 4.