Interview questions and model answers
"Merge vs rebase — which do you use?"
Merge preserves history exactly, including a merge commit with two parents; rebase replays my commits on top of the target branch to produce linear history with new commit hashes. I rebase my own feature branch onto main to keep it current and clean it up with interactive rebase before review, but I never rebase commits others have based work on. For integrating PRs we use squash or merge commits per team convention, with branch protection enforcing CI and reviews.
"How do you undo a bad commit that's already pushed to main?"
git revert that commit — it creates a new inverse commit without rewriting shared history, so nobody has to recover. For a merge commit, git revert -m 1. In GitOps, that revert is also the rollback: Flux reconciles the previous state.
"What's the difference between reset --soft, --mixed and --hard?"
All move the current branch pointer. Soft keeps the changes staged, mixed (the default) keeps them in the working tree but unstaged, and hard discards them from both — the only destructive one. Even after a hard reset, committed work can usually be recovered from the reflog.
"Someone committed an AWS key to the repo. What do you do?"
Rotate or deactivate the key immediately and check CloudTrail for misuse — removing it from Git doesn't help if it's already been copied. Then remove it from history with git filter-repo or BFG if policy requires, force-push, and have everyone re-clone. Prevent it with pre-commit secret scanning, GitHub push protection and getting secrets from Secrets Manager at runtime. Better still, use OIDC so there are no long-lived keys to leak.
"Trunk-based development or GitFlow?"
For services delivered continuously, trunk-based: short-lived branches merged daily, main always releasable, feature flags for unfinished work, tags for releases. It minimises merge pain and fits GitOps. GitFlow fits products with scheduled, versioned releases and several supported versions, but its long-lived branches slow integration.
"How would you find which commit introduced a bug?"
git bisect between a known good and a known bad commit — it binary-searches history, and git bisect run automates it with a test script. For a specific line, git blame and git log -S to find when a string appeared.
"Your CI uses shallow clones and versioning from tags broke. Why?"
git describe and changed-file detection need history and tags that a depth-1 clone doesn't have. I'd fetch full history or enough depth plus tags — fetch-depth: 0 in GitHub Actions — only in the jobs that need it.
"How do you structure a GitOps config repo for multiple environments?"
One main branch with a directory per environment — Kustomize base plus overlays for dev, staging and prod — rather than environment branches, which drift and cause messy merges. Promotion is a PR that changes the image tag or values in the next environment's overlay, with CODEOWNERS and required reviews for production paths.