53 Git interview questions with answers
53 Git interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All Git interview questions
What is Git Flow? What are the popular branching strategies?
How are git rebase and merge different? When should you use each?
How do Git Flow and trunk-based development differ, and when do you use each?
GitHub Flow vs Git Flow: which should a 5-person startup choose and why?
Your feature branch has lived 2 weeks and is now 50 commits behind main. What strategy merges it safely?
Multi-team monorepo: what branching strategy fits and how do you prevent teams from blocking each other?
Production has a critical bug at 2am during an active sprint. What is the correct hotfix process?
What is the purpose of a release branch? When is it needed vs. unnecessary overhead?
Branch protection rules on GitHub: what should you configure to prevent the team from pushing directly to main?
Polyrepo vs Monorepo: how do git workflows differ and when should you migrate?
What are Conventional Commits? Why enforce them with commitlint rather than just team agreement?
Interactive rebase: how do you use squash, fixup, reword, drop to clean up history before merging a PR?
When should you squash merge a PR instead of using a merge commit? What are the trade-offs?
You just made a bad commit (wrong message or forgot a file). How do you fix it without creating a new commit?
I accidentally ran `git reset --hard` and lost 3 unpushed commits. How do I recover?
What are signed commits with GPG/SSH? When should an enterprise team enforce them?
What are atomic commits? Why is a commit like "feat: add user auth + fix navbar + update deps" an anti-pattern?
How does the CODEOWNERS file work? How do you use it to enforce precise reviews in a large team?
Merge vs Rebase: when to use which? Explain the golden rule of rebasing.
You hit complex conflicts across many commits during a rebase. What strategy avoids "rebase hell"?
Fast-forward merge vs no-ff merge: what is the difference? What does GitHub use by default and why should teams choose deliberately?
What is a 3-way merge? How does git auto-resolve, and when must you resolve manually?
What is `git rerere`? When does it save you from resolving the same conflict multiple times?
Merging a feature branch into main, you hit a conflict where both sides refactored the same file. What is the safe resolution process?
Undoing a public commit already merged into main: revert vs reset — when to use which?
Interactive rebase edit mode: what can it do that squash cannot?
A teammate just force-pushed to a shared branch, losing your commits. How do you recover?
How does `git bisect` work? Give a real-world scenario of using it to find a regression commit.
What are `git log -S` and `git log -G` used for? When do they save you during debugging?
A branch was accidentally deleted before being merged anywhere. How do you recover it?
`git blame` in practice: it is not just for blaming — what are the genuinely useful use cases?
You discover a bug right after a production deploy and need to rollback immediately. `git revert` or redeploy from the previous tag?
`--force` vs `--force-with-lease`: why is force-with-lease safer and how should a team enforce it?
When is a force push acceptable and when is it absolutely not allowed?
You accidentally force-pushed to main and the history was overwritten. What is the emergency recovery process?
You accidentally committed a `.env` file with credentials to remote. How do you handle it?
A large file was accidentally committed into git history, making the repo heavy. How do you remove it from history without disrupting collaboration?
What is `git worktree`? When is it better than stashing or creating a second clone?
Advanced `git stash`: push, pop, apply, list, show, drop — what real-world patterns do you need to know?
`git cherry-pick` in practice: when is it the right tool and when is it a sign of a branching strategy problem?
Partial clone and shallow clone: when do you use them in CI/CD to speed up pipelines?
Git submodules vs git subtrees: why do most teams avoid both?
What is Git LFS? Practical setup for a project with large design files and build artifacts?
Why does `git pull` often create unnecessary merge commits and how do you fix it with `--rebase`?
Setting up a pre-commit hook with Husky + lint-staged: why lint only staged files instead of the whole project?
commit-msg hook with commitlint: how to set it up and how to not block developers for WIP commits?
Pre-push hook to run tests: what are the trade-offs and how do you configure it so it does not slow down the developer workflow?
semantic-release: how do you automate versioning and CHANGELOG generation from conventional commits?
Server-side hooks (GitHub Actions) vs client-side hooks (Husky): what should each enforce?
What is the difference between `git fetch` and `git pull`? When should you only fetch?
When does a merge conflict happen? What is the basic process to resolve one?
What is a detached HEAD? How do you check out an old commit to inspect code and then return?
A file was committed by mistake (e.g. `node_modules/`, a log file) — you added it to `.gitignore` but git still tracks it. How do you fix it?