Git Interview Questions & Answers: Rebase, Merge, Reflog & GitOps
Git is the foundation of every DevOps workflow. But "I know Git" for an interview means more than
knowing git commit and git push. Interviewers at product companies test
your understanding of branching strategies, history manipulation, internal data structures, and
how Git integrates into CI/CD and GitOps workflows. This guide covers every question I have
encountered or asked in real DevOps interviews.
How Git Stores Data — The Foundation
Understanding Git internals is what separates senior engineers from juniors in interviews. Git does not store differences (diffs). It stores snapshots. Every commit is a snapshot of the entire repository at that point in time. Git uses a Directed Acyclic Graph (DAG) where each commit points to its parent(s). A branch is simply a lightweight, movable pointer to a commit.
.git/objects/, addressed by their SHA-1 hash.
Merge vs Rebase — The Most Asked Question
This is the most common Git interview question in DevOps and SRE roles. The answer requires understanding both the mechanics and the appropriate use case for each.
git merge
Merge combines two branches by creating a new merge commit that has two parents. The branch history is fully preserved — you can see exactly when the feature branch was created and when it was merged. The history is non-linear (has a branch topology in the graph). Use merge when you want to preserve the full history of what happened and when.
git rebase
Rebase replays commits from one branch on top of another, creating new commits with different SHAs but the same changes. The result is a perfectly linear history with no merge commits. Use rebase to keep a feature branch up-to-date with main before raising a PR, or to squash WIP commits before merging.
Branching Strategies
GitFlow
GitFlow uses two permanent branches (main and develop) plus three supporting
branch types (feature, release, hotfix). Features branch from develop and merge back.
Releases branch from develop, get stabilised, and merge to both main and
develop. Hotfixes branch from main directly.
Best for: Products with distinct release versions (mobile apps, desktop software, SaaS with versioned APIs). Not good for: Web services with continuous deployment — long-lived branches create merge conflicts and delay integration.
Trunk-Based Development
All developers commit to a single trunk branch (main) daily. Feature flags hide incomplete features from users without hiding them from deployment. Feature branches are very short-lived (hours, not days). This is the branching strategy used by Google, Facebook, and most DevOps-mature organisations.
Best for: Teams with CI/CD, high deployment frequency, strong test coverage. Requires feature flags and a mature CI pipeline to be safe.
Essential Git Commands for DevOps
Git in GitOps Workflows
In a GitOps workflow (ArgoCD, Flux), Git is not just version control — it is the control plane for
all infrastructure and application deployments. The CI pipeline updates image tags in the GitOps
repository by committing directly. ArgoCD detects the commit and applies the change to Kubernetes.
Rollback = git revert. Audit trail = Git history.
Interview Q&A
git checkout <sha> or git checkout v1.0.0. Any commits you make are not attached to any branch and will be garbage-collected eventually. To save your work: git checkout -b new-branch-name to create a branch at the current position.git reflog shows every HEAD position for the last 90 days. Find the SHA of the last commit on the deleted branch, then git checkout -b recovered-branch <sha>. If the branch was pushed to a remote before deletion, git checkout -b recovered-branch origin/deleted-branch may still work if the remote has not been pruned. Always push feature branches to remote before deleting locally — this is the real safety net.🌿 Explore Git on the Interactive Mind Map
See how Git connects to GitHub Actions, Jenkins, ArgoCD, and SonarQube — the full DevOps toolchain.
Open Interactive Mind Map Next: CI/CD Guide →Git is where every CI/CD pipeline starts. Learn how code goes from a git push all the way to production with CI/CD →
📩 Get Free DevOps Interview Notes
Cheat sheets, real commands, interview Q&As — free.
No spam · Follow @master.devops for daily tips
How Git Works Internally
Most engineers use Git every day without understanding what happens under the hood. Understanding Git's internal model — objects, references, and the index — makes you dramatically better at resolving complex situations like merge conflicts, accidental commits, and corrupted histories.
Rebase vs Merge — When to Use Each
This is one of the most common Git questions in DevOps interviews. The answer is not "always rebase" or "always merge" — it depends on context. Understanding the trade-offs is what interviewers test for.
| Scenario | Merge | Rebase |
|---|---|---|
| Integrating completed feature → main | ✅ Preserves audit trail | Loses branch context |
| Syncing local feature with latest main | Creates noisy merge commits | ✅ Keeps linear history |
| Shared/public branch (main) | ✅ Safe | ❌ Never rebase shared branches |
| Local WIP commits before PR | Unnecessary | ✅ Squash with interactive rebase |
git reflog — Your Safety Net
git reflog records every HEAD movement for 90 days, regardless of whether the commit is
reachable from any branch. This is the most important command for recovering from disasters.
git rev-parse HEAD. If anything breaks, git reset --hard <that-sha> will restore you.
Branching Strategies in DevOps Teams
| Strategy | Best For | Trade-off |
|---|---|---|
| Trunk-Based | Teams deploying multiple times/day | Requires feature flags and strong test coverage |
| GitFlow | Scheduled releases, multiple versions in prod | Overhead of develop/release/hotfix branches |
| GitHub Flow | Continuous deployment, single prod version | Less structure around releases |
Git Interview Questions & Answers
git checkout <sha> or checkout a tag. Any commits made in this state are not tracked by any branch and will be lost after switching away. Fix: git checkout -b new-branch to capture your work, or git checkout main to discard. Work can always be recovered from reflog.git reset moves HEAD backwards — it rewrites history. --soft keeps staged changes, --mixed unstages, --hard discards everything. Never use reset on shared branches. git revert <sha> creates a new commit that undoes the target — history is preserved. The rule: reset for local/private branches only, revert for anything pushed to shared remotes.git rebase -i HEAD~N where N is the number of commits to squash. In the interactive editor, change pick to squash on commits to combine into the previous one. After saving, Git opens another editor to write the combined commit message. GitHub/GitLab also offer a "Squash and merge" button on pull requests.git cherry-pick <sha> applies a specific commit to the current branch. Useful for backporting a bug fix from main to a release branch without merging everything else. git cherry-pick A..B applies a range. If conflicts arise: resolve → git cherry-pick --continue. Cherry-picking creates a new commit with a new SHA — the original commit remains unchanged on its source branch.