Git Interview Questions & Answers (2026)
These interviews test your understanding of version control fundamentals, branching strategies, conflict resolution, and repository maintenance. Demonstrate clear command knowledge, explain why you choose specific workflows, and show awareness of performance implications. Focus on practical examples, articulate trade‑offs, and convey how you ensure code integrity in team environments to impress interviewers.
19 questions · updated Aug 29, 2026
Quick facts
| Typical rounds | Phone screen, technical coding, system design, and final onsite |
| Core topics | Branching, merging, rebasing, stash, remote management |
| Preferred experience | 2‑5 years of daily Git usage in collaborative projects |
Questions
Beginner
What is the difference between git merge and git rebase?
git merge creates a new commit that combines the histories of two branches, preserving the original commit sequence. git rebase rewrites the target branch by moving its commits onto the tip of another branch, producing a linear history. Interviewers want to hear that merge is safe for shared branches because it does not rewrite history, while rebase is useful for cleaning up local commits before integration, but must be avoided on public branches to prevent divergence.
git merge feature-branch
git rebase mainHow does git stash work and when would you use it?
git stash saves uncommitted changes in a stack-like structure, allowing you to revert the working directory to the last commit without losing work. You can later apply or pop the stash to restore changes. This is useful when you need to switch branches quickly or pull remote updates while preserving incomplete work. Interviewers look for awareness of stash list, stash pop vs. apply, and the impact on the index.
git stash push -m "WIP"
git stash list
git stash popExplain the purpose of git reflog and a scenario where it is essential.
git reflog records updates to the HEAD reference, including commits that are no longer reachable from any branch. It enables recovery of lost commits after a reset, rebase, or accidental checkout. A common scenario is undoing a git reset --hard that removed recent work; reflog lets you locate the previous HEAD and restore the commit. Interviewers expect you to demonstrate using reflog to find a SHA and then git checkout or cherry-pick it.
git reflog
git checkout <sha>What is a detached HEAD state and how do you safely exit it?
A detached HEAD occurs when HEAD points directly to a commit instead of a branch reference, often after checking out a specific commit or tag. In this state, new commits are not attached to any branch and can be lost if not referenced. To exit safely, either create a new branch from the current commit (git checkout -b new-branch) or return to an existing branch (git checkout main). Interviewers look for awareness of potential data loss and proper recovery steps.
git checkout -b temp-fix
git checkout mainHow do you resolve a merge conflict in Git?
When Git cannot automatically merge changes, it marks conflicted files with conflict markers (<<<<<<<, =======, >>>>>>>). Resolve by editing the file to keep the desired code, removing markers, then add the file (git add) and commit the merge. You can also use mergetool or rebase --abort if needed. Interviewers expect you to describe the process, mention checking git status, and optionally using visual tools for efficiency.
git status
git add conflicted-file
git commitWhat is the difference between git pull and git fetch?
git fetch downloads objects and refs from a remote repository but does not integrate them into the current branch, leaving you in a detached state to review changes. git pull combines fetch with an automatic merge (or rebase) into the current branch. Interviewers want you to emphasize that fetch gives you control to inspect before merging, reducing unexpected conflicts, while pull is a shortcut for routine updates.
git fetch origin
git merge origin/main
git pullIntermediate
Describe how you would set up a Git workflow for a large team with multiple releases.
A common approach is Git Flow: maintain a long‑living 'main' branch for production, a 'develop' branch for integration, and feature branches for individual work. Release branches are created from develop when preparing a version, allowing stabilization without halting new features. Hotfix branches branch off main for urgent patches. This structure isolates work, enables parallel releases, and provides clear merge paths. Interviewers look for justification of isolation, ease of versioning, and awareness of potential merge overhead.
When would you prefer git rebase over merge in a collaborative environment?
Rebase is preferred for cleaning up a series of local commits before sharing them, creating a linear history that simplifies bisecting and log reading. In a collaborative setting, you can rebase feature branches onto the latest develop before opening a pull request, ensuring the PR contains a single, tidy commit series. However, you must avoid rebasing branches that are already pushed and used by others, as rewriting shared history can cause coordination problems.
git fetch origin
git rebase origin/developHow can you limit the size of a Git repository and why is it important?
Large repositories slow down clone, fetch, and CI pipelines. To limit size, use .gitignore to exclude binaries, employ Git LFS for large assets, and periodically run git gc --aggressive to prune unreachable objects. Splitting monolithic repos into micro‑repos or using submodules can also help. Interviewers expect you to discuss storage impact, network latency, and maintainability, showing that you proactively manage repo bloat.
Explain how you would cherry-pick a commit from one branch to another and the risks involved.
git cherry-pick <sha> applies the changes introduced by a specific commit onto the current branch, creating a new commit with a different SHA. This is useful for back‑porting bug fixes. Risks include duplicate code if the original commit later merges, potential conflicts if the surrounding code differs, and loss of context about why the change was made. Interviewers want you to mention checking the commit’s dependencies and testing after the pick.
git checkout release-branch
git cherry-pick abc123What is a Git submodule and when would you use it?
A submodule embeds another Git repository at a specific commit within a parent repo, allowing you to treat external code as a dependency while preserving its history. Use it when you need to include a library that evolves independently, such as a shared UI component, without merging its history. Interviewers look for awareness of submodule init, update, and the need to commit the submodule pointer after changes.
git submodule add https://github.com/example/lib.git libs/libHow does Git handle binary files and what strategies improve performance?
Git stores binary files as whole objects, leading to large diffs and repository bloat. To improve performance, use .gitattributes to mark binaries, employ Git LFS to store large files externally, and avoid committing generated binaries. Additionally, configure diff drivers to treat binaries as binary, preventing costly diff calculations. Interviewers expect you to discuss storage overhead, network impact, and the trade‑offs of LFS versus plain Git.
Advanced
What are the implications of using git commit --amend on a shared branch?
git commit --amend rewrites the most recent commit, creating a new SHA. On a shared branch, this rewrites history that others may have based work on, causing divergence and requiring force‑pushes. If teammates have already pulled the original commit, they will encounter non‑fast‑forward errors and must rebase or reset, leading to potential data loss. Interviewers want you to stress avoiding amend on public branches and using it only for local corrections.
Explain the concept of a fast‑forward merge and when it is not possible.
A fast‑forward merge occurs when the target branch’s HEAD is an ancestor of the source branch, allowing Git to simply move the pointer forward without creating a merge commit. It is not possible when the target branch has diverged—i.e., both branches have unique commits—requiring a true merge commit to combine histories. Interviewers look for clarity on linear history, the role of --no-ff to force a merge commit, and impact on auditability.
How would you troubleshoot a situation where git push is rejected with ‘non-fast-forward’?
A non‑fast‑forward rejection means the remote contains commits not present locally. Resolve by fetching the remote (git fetch), reviewing the new commits (git log origin/branch), then either merging (git merge origin/branch) or rebasing (git rebase origin/branch) to integrate them. After resolving conflicts, push again. Interviewers expect you to mention the importance of communication with teammates before force‑pushing and using --force-with-lease as a safe alternative when history rewrite is intentional.
What is the purpose of the .gitkeep file?
.gitkeep is a conventionally named empty file used to add otherwise empty directories to a Git repository, because Git does not track empty folders. By placing .gitkeep in the directory and committing it, the folder is preserved across clones. Interviewers look for understanding that .gitkeep is not a built‑in feature but a community practice, and that .gitignore can be used to exclude it if desired.
Describe how you would use git bisect to locate a bug introduced in a large codebase.
git bisect performs a binary search through commit history to find the first bad commit. Start with git bisect start, then mark the current HEAD as bad (git bisect bad) and a known good commit (git bisect good <sha>). Git checks out a midpoint; you test and mark good or bad, repeating until the offending commit is isolated. Interviewers expect you to mention automating tests with git bisect run and the importance of reproducible test cases.
How does Git’s internal object model (blob, tree, commit, tag) enable efficient storage?
Git stores content as immutable objects identified by SHA‑1 hashes. Blobs hold file data, trees represent directory structures referencing blobs and sub‑trees, commits point to a tree plus parent commits, and tags reference commits. Because identical content yields identical hashes, Git deduplicates data, storing each unique blob once. This model enables cheap snapshots, fast branching, and efficient diffing. Interviewers look for explanation of content‑addressable storage and its impact on performance.
What are the security considerations when using Git over HTTP vs. SSH?
HTTP(S) transmits credentials via basic auth or token, which can be intercepted if not using TLS, while SSH uses key‑based authentication, providing stronger identity verification and encrypted transport. SSH also allows fine‑grained access control via authorized_keys. Interviewers expect you to discuss the risk of credential leakage, the benefits of SSH agent forwarding, and the practice of disabling password authentication for better security.
Common mistakes
- Rebasing public branches and causing history divergence
- Committing large binary files without using Git LFS
- Forgetting to resolve all conflict markers before committing
- Using git pull without understanding it performs an automatic merge
Study plan
- Review core commands and practice each in a sandbox repo
- Master branching strategies by simulating feature, release, and hotfix flows
- Solve real‑world conflict scenarios and perform rebases, merges, and cherry‑picks
- Learn advanced tools: reflog, bisect, submodules, and LFS
- Mock interview: answer questions aloud, focusing on reasoning and trade‑offs
FAQ
How many Git commands should I memorize for an interview?
Focus on understanding rather than rote memorization. Know the purpose, typical options, and trade‑offs for about 15 core commands such as clone, add, commit, push, pull, fetch, merge, rebase, stash, tag, bisect, and log. Being able to explain when and why to use each demonstrates competence.
Is it okay to use GUI tools during a coding interview?
Most interviewers expect you to work from the command line to show familiarity with Git’s textual interface. If a GUI is allowed, be prepared to explain the equivalent CLI commands, as interviewers often probe your understanding of underlying operations.
What is the best way to demonstrate Git knowledge in a live coding session?
Narrate your actions: type the command, describe its effect, and explain why you chose it. Show awareness of edge cases, such as handling conflicts or avoiding history rewrites on shared branches. This verbal walkthrough signals depth of understanding.
How important is Git LFS for a typical software engineering role?
Git LFS is essential when the codebase includes large assets like media or model files. For most backend or web roles, basic Git knowledge suffices, but mentioning LFS shows awareness of repository performance and scalability concerns.
Can I skip learning about submodules if I never used them?
Even if you haven’t used submodules, interviewers may ask to gauge your ability to handle external dependencies. Knowing the basic commands (add, update, init) and their pitfalls demonstrates adaptability and a well‑rounded skill set.
Related
Ready for your next interview?
Download MiPrep AI. Load your resume and the job description. Show up ready.
Free tier · No credit card · macOS 14+ · Windows 10+
Free tier · No credit card · Runs on your Mac or Windows machine