60+ Advanced Git Interview Questions with Answers (2027)

62 advanced Git interview questions: object model, reflog recovery, rebase --onto, rerere, merge strategies, filter-repo, partial clone, signing.

Sep 12, 2025 - 13:45
Nov 11, 2026 - 13:34
 0  184
TOPICInterview Q & APractical guide
60+ Advanced Git Interview Questions with Answers (2027)

Advanced Git interview questions go past add, commit and push. Interviewers ask how Git stores objects, how merges and rebases really work, how to recover lost work with the reflog, how to rewrite history safely, how to keep huge repositories fast with partial clone and sparse checkout, and how to sign and protect commits. This page answers 62 such questions.

If you need the full range from basics to GitHub workflows, start with our main Git and GitHub interview questions (90+). This page assumes you know daily Git and concentrates on internals, history surgery, performance at scale, security and automation. Commands were checked against the Git reference documentation in November 2026. For day-to-day command practice see 25 Git commands every DevOps engineer must know.

Key takeaways

  • Git is a content-addressed object store of blobs, trees, commits and tags; branches and tags are just refs pointing at commits.
  • Almost nothing committed is truly lost for a while: the reflog and git fsck can find unreachable commits until garbage collection prunes them.
  • The default merge strategy is ort (since Git 2.34). Rebase replays commits and creates new IDs, so never rebase commits others have built on.
  • Large repositories stay fast with partial clone, sparse checkout, commit-graph, git maintenance and Scalar.
  • Commits can be signed with GPG, SSH or X.509 keys; use git filter-repo, not filter-branch, for history rewrites.

Advanced Git topics and the commands behind them

TopicCommands to knowTypical question
Internalscat-file, hash-object, ls-tree, rev-parseWhat is inside a commit object?
Recoveryreflog, fsck --lost-found, resetHow do you recover a deleted branch?
History rewritingrebase -i, commit --fixup, filter-repoHow do you remove a secret from history?
Integrationmerge, rerere, range-diff, cherry-pickHow do you compare two versions of a rebased branch?
Scaleclone --filter, sparse-checkout, maintenance, scalarHow do you make a monorepo clone fast?
Securitycommit -S, verify-commit, push --force-with-leaseHow do you prove who wrote a commit?
Debuggingbisect run, blame -C, log -S, log -LHow do you find the commit that introduced a bug?

Foundations interviewers check first (freshers moving to advanced)

1. What are the four Git object types?

Blob (file content), tree (a directory listing of names, modes and object IDs), commit (a tree pointer, parent commits, author, committer and message) and annotated tag (a named, optionally signed pointer to another object). All are stored by the hash of their content.

2. How do you look inside an object?

git cat-file -t <id> shows the type, and git cat-file -p <id> prints the content.

git cat-file -p HEAD          # commit: tree, parent, author, message
git cat-file -p 'HEAD^{tree}' # tree entries
git ls-tree -r --name-only HEAD

3. What is a ref?

A name that points to an object ID. Branches live under refs/heads/, remote-tracking branches under refs/remotes/ and tags under refs/tags/. Refs are stored as loose files or in packed-refs, and newer Git versions also support the reftable backend.

4. What is HEAD and what is a detached HEAD?

HEAD normally points to a branch ref, so new commits move that branch. A detached HEAD points straight at a commit, for example after checking out a tag. Commits made there belong to no branch and can be lost unless you create a branch with git switch -c.

5. What is the index?

The staging area, stored in .git/index. It records the exact content of the next commit. git add writes blobs and updates the index; git commit turns the index into a tree.

6. What do ~ and ^ mean in revisions?

HEAD~2 is the grandparent following first parents. HEAD^2 is the second parent of a merge commit. HEAD^ equals HEAD~1. See gitrevisions for the full syntax.

7. What is the difference between A..B and A...B in git log?

A..B lists commits reachable from B but not from A, which means what B has that A does not. A...B lists commits reachable from either but not both, the symmetric difference. With git diff, A...B diffs B against the merge base.

8. What is the merge base?

The best common ancestor of two commits, found with git merge-base A B. Three-way merges compare both sides against it.

9. What is the reflog?

A local log of where HEAD and each branch pointed over time. git reflog shows entries such as HEAD@{3}. Entries expire (by default after 90 days for reachable and 30 days for unreachable commits) and are never pushed.

10. What are the three modes of git reset?

--soft moves the branch only, --mixed (default) also resets the index, and --hard also resets the working tree, discarding uncommitted changes.

11. What is the difference between revert and reset?

git revert adds a new commit that undoes an earlier one and is safe on shared branches. git reset moves the branch pointer and rewrites local history, which is only safe for commits nobody else has.

12. What are git switch and git restore?

Commands added in Git 2.23 to split up checkout. switch changes branches; restore restores files in the working tree or index, for example git restore --staged file.

13. What is a fast-forward merge?

When the target branch has no new commits since the feature branched off, Git just moves the branch pointer forward. No merge commit is created unless you pass --no-ff.

14. What does git stash store?

Stashes are commits stored under refs/stash that record the index and working tree (and untracked files with -u). git stash pop applies and drops; git stash apply keeps the entry.

Advanced Git questions for 2 to 5 years of experience

15. How does interactive rebase work?

git rebase -i <base> opens a todo list of commits after the base. You can pick, reword, edit, squash, fixup, drop or reorder them, and add exec lines to run commands. Git then replays the commits one by one, creating new commit IDs.

16. What are fixup commits and autosquash?

git commit --fixup=<sha> creates a commit marked to be folded into an earlier one. Later, git rebase -i --autosquash <base> moves and squashes it automatically. Set rebase.autoSquash=true to make it the default.

17. What does git rebase --onto do?

It moves a range of commits to a new base. git rebase --onto main feature-a feature-b takes the commits on feature-b that are not on feature-a and replays them onto main. It is useful when a branch was built on another branch that has since been merged or dropped.

18. What does --update-refs do during a rebase?

Added in Git 2.38, it updates any other local branches that point into the rebased range, so a stack of dependent branches moves together. Set rebase.updateRefs=true to make it the default for stacked work.

19. What is git rerere?

"Reuse recorded resolution". With rerere.enabled=true, Git records how you resolved a conflict and applies the same resolution next time the same conflict appears, which helps with repeated rebases of long-running branches.

20. Which merge strategies does Git have?

ort is the default for two heads since Git 2.34, replacing recursive. octopus merges more than two heads without conflicts, ours keeps the current tree entirely, and subtree handles merging into a subdirectory. Strategy options such as -X ours or -X theirs only resolve conflicting hunks.

21. What is the difference between -s ours and -X ours?

-s ours creates a merge commit but ignores all changes from the other branch. -X ours merges normally and only uses our side for hunks that conflict.

22. How do you compare two versions of a rebased branch?

git range-diff compares two commit ranges commit by commit, for example git range-diff main origin/feature feature. Reviewers use it to see what changed between versions of a force-pushed pull request.

23. How do you recover a branch you deleted?

Find its last commit in git reflog (or in the deletion message, which prints the SHA), then recreate it with git branch feature <sha>. If the reflog has no entry, git fsck --lost-found lists dangling commits.

24. How do you undo a bad git reset --hard?

Run git reflog, find the entry before the reset (for example HEAD@{1}) and run git reset --hard HEAD@{1}. Uncommitted working-tree changes are not in the reflog; only staged content might be found as dangling blobs with git fsck.

25. How do you search history for when a string was added or removed?

The pickaxe options: git log -S 'API_KEY' finds commits that change the number of occurrences of a string, and git log -G 'regex' finds commits whose diff lines match a regular expression. git log -L :funcName:file.c traces the history of one function.

26. How does git blame handle moved code?

git blame -C detects lines moved or copied from other files in the same commit; repeating -C widens the search. -w ignores whitespace changes, and --ignore-revs-file skips bulk formatting commits listed in a file such as .git-blame-ignore-revs.

27. How do you automate git bisect?

Give it a script that exits 0 for good and 1 to 127 (except 125) for bad; exit code 125 means "skip this commit".

git bisect start HEAD v3.2.0
git bisect run ./ci/test-login.sh
git bisect reset

28. What is git worktree?

It lets one repository have several working directories, each on a different branch, sharing the same object database. git worktree add ../hotfix release/3.2 lets you fix production without stashing your current work.

29. Submodules or subtrees: what is the difference?

AspectSubmoduleSubtree
StorageParent stores a commit pointer (gitlink) plus .gitmodulesFiles are copied into the parent's history
CloneNeeds --recurse-submodules or git submodule update --initNormal clone has everything
PinningExact commit of the child repositoryWhatever was last merged in
Contributing backWork inside the submodule repogit subtree push or manual

30. How do you push a rewritten branch safely?

Use git push --force-with-lease, which refuses to overwrite the remote branch if it moved since you last fetched. Add --force-if-includes (Git 2.30+) so a background fetch does not silently make the lease pass.

31. What are Git hooks and where do they run?

Scripts in .git/hooks (or a directory set by core.hooksPath) that run on events such as pre-commit, commit-msg, pre-push and, on servers, pre-receive and update. Client hooks are not cloned and can be skipped with --no-verify, so enforce rules in CI or server-side as well.

32. How do you share hooks with a team?

Commit them in a directory such as .githooks/ and have each developer run git config core.hooksPath .githooks, or use a framework such as pre-commit. Mirror critical checks in CI because local hooks are optional.

33. What do git notes and git replace do?

Notes attach extra text to commits without changing their IDs, stored under refs/notes/. Replace makes Git substitute one object for another when reading, which can graft histories together. Both are niche and not shared unless you push their refs explicitly.

34. How do you cherry-pick a merge commit?

Specify the mainline parent: git cherry-pick -m 1 <merge-sha> applies the changes the merge introduced relative to its first parent. Use -x to record the original commit ID in the message.

35. What is .gitattributes used for?

Per-path settings such as line ending normalisation (text=auto, eol=lf), binary handling, diff drivers, merge drivers (for example merge=ours for generated files), export rules and Git LFS tracking.

36. How does Git LFS work?

Git LFS replaces large files in the repository with small pointer files and stores the content on an LFS server. It uses clean and smudge filters configured in .gitattributes, for example *.psd filter=lfs diff=lfs merge=lfs -text. The hosting platform must support it.

Senior advanced Git interview questions

37. How does Git store objects efficiently?

New objects are written as zlib-compressed loose files. git gc and git repack combine them into packfiles with delta compression, where similar objects are stored as differences from a base. Pack index files (.idx) and the multi-pack index allow fast lookup.

38. What is the commit-graph file?

A file that stores commit parents, root trees and generation numbers in a compact format, which speeds up history walks such as git log --graph, merge-base calculation and reachability checks. git commit-graph write or background maintenance keeps it updated.

39. What does git maintenance do?

git maintenance start registers the repository and schedules background tasks such as prefetch, commit-graph updates, loose-object cleanup and incremental repack, using cron, launchd or the Windows Task Scheduler. It keeps large repositories fast without blocking commands.

40. How do partial clone and shallow clone differ?

A shallow clone (--depth 1) cuts off history, which breaks or slows some operations such as merge-base and blame. A partial clone (--filter=blob:none) keeps full commit history but downloads file contents on demand. Partial clone is generally better for developers; shallow clone is common in CI.

41. How does cone-mode sparse checkout work?

You list directories, and Git checks out only those plus top-level files. Cone mode uses directory patterns, which makes pattern matching fast on big repositories. It combines well with partial clone.

git clone --filter=blob:none --sparse https://example.com/org/mono.git
cd mono
git sparse-checkout set services/billing libs/auth

42. What is Scalar?

A tool shipped with Git since 2.38 that configures a repository for scale: partial clone, sparse checkout, commit-graph, multi-pack index, background maintenance and the file system monitor where available. scalar clone <url> sets it all up (scalar docs).

43. What is the built-in file system monitor?

With core.fsmonitor=true on macOS and Windows, Git runs a daemon that tracks changed files, so git status does not have to scan the whole working tree. Pair it with core.untrackedCache=true on large trees.

44. How do you remove a secret or large file from all of history?

First rotate the secret, because anyone who cloned may already have it. Then rewrite history with git filter-repo, which the Git documentation recommends over filter-branch, force-push all affected refs, ask collaborators to re-clone, and ask the hosting provider to purge cached views if needed.

git filter-repo --invert-paths --path config/prod.env
git filter-repo --strip-blobs-bigger-than 50M

45. How do you sign commits and tags, and which key types are supported?

Git can sign with OpenPGP (GPG), SSH keys (since Git 2.34) or X.509 certificates through gpg.format. Use git commit -S and git tag -s, or set commit.gpgsign=true. Verify with git verify-commit, git log --show-signature and, for SSH, a gpg.ssh.allowedSignersFile.

46. Why is a commit author not proof of identity?

Author and committer names and emails come from local configuration and can be set to anything. Only a signature verified against a trusted key, or the hosting platform's record of who pushed, ties a commit to a person. Platforms can require signed commits through branch protection or rulesets.

47. What is the status of SHA-256 in Git?

Git can create SHA-256 repositories with git init --object-format=sha256 since 2.29, and interoperability work continues. Most hosting platforms still use SHA-1 repositories, which Git protects with a collision-detecting SHA-1 implementation. Check platform support before adopting SHA-256 (hash function transition).

48. How do you enforce policy on the server side?

On self-hosted servers, pre-receive or update hooks can reject pushes (for example unsigned commits or files over a size). On hosted platforms, use protected branches or rulesets, required status checks, push protection for secrets and code owner reviews.

49. What does git merge-tree --write-tree do?

Since Git 2.38 it performs a merge without touching the working tree or index and prints the resulting tree ID, plus conflict information. Servers and bots use it to check whether a pull request merges cleanly.

50. How would you migrate a large repository from another VCS to Git?

Choose whether to keep full history, map authors to emails, convert with a tool suited to the source (for example git svn for Subversion), move large binaries to Git LFS during conversion, verify file trees at key revisions, freeze the old system for a cut-over, and set up branch protection and CI before announcing.

Scenario-based advanced Git questions

51. You force-pushed over a colleague's commits on a shared branch. How do you fix it?

Ask the colleague for their local branch, or find the old tip in your reflog for the remote-tracking branch (git reflog show origin/feature), or in the platform's activity log. Restore it with a push of that SHA, then protect the branch and switch to --force-with-lease.

52. A merge to main introduced a bug and other commits followed. How do you undo only the merge?

Run git revert -m 1 <merge-sha>. Remember that re-merging the same branch later will not bring those changes back, because Git sees them as already merged; revert the revert first, then merge the fixes.

53. Your git status takes 20 seconds in a monorepo. What do you try?

Enable core.fsmonitor and core.untrackedCache, use sparse checkout for the areas you work on, run git maintenance start, check for a huge untracked directory that should be in .gitignore, and consider re-cloning with Scalar.

54. CI clones take minutes. How do you shorten them?

Use a shallow clone (--depth 1) or a blobless partial clone, fetch only the needed ref, cache the repository on runners, and use sparse checkout if the job needs only part of a monorepo. Keep enough history if the job computes versions from tags.

55. An API key was pushed to a public repository ten minutes ago. What is the order of actions?

Revoke and rotate the key first, check provider logs for misuse, then remove it from history with git filter-repo and force-push, and enable secret scanning push protection. Removing the commit without rotating does not help, because the key may already be copied.

56. A long-lived release branch needs the same conflict resolved after every rebase. What helps?

Enable rerere so resolutions are reused, shorten the branch's life, and consider merging main into it instead of rebasing if history is shared. Fix the root cause in main where possible so the conflict disappears.

57. You need to split one large commit into three logical commits. How?

Start git rebase -i, mark the commit as edit, run git reset HEAD^ to unstage its changes, then stage and commit pieces with git add -p, and finish with git rebase --continue.

58. A file's history seems to stop at a rename. How do you see the full history?

Use git log --follow -- path/to/file, which follows renames for a single file. Rename detection depends on similarity, so a rename combined with heavy edits may not be detected; making the rename a separate commit avoids that.

59. Developers keep committing unformatted code. How do you enforce formatting?

Provide a shared pre-commit hook via core.hooksPath or the pre-commit framework, run the same formatter check as a required CI status, and add the one-off reformatting commit to .git-blame-ignore-revs so blame stays useful.

60. A submodule shows as modified but you changed nothing. What happened?

The submodule's checked-out commit differs from the one recorded in the parent, often after pulling the parent without updating submodules. Run git submodule update --init --recursive, or commit the new pointer if the change is intended. Setting submodule.recurse=true helps prevent it.

61. You need to know which release first contained a fix. How do you find it?

Run git tag --contains <sha> to list tags that include the commit, or git describe --contains <sha> for the first one. If the fix was cherry-picked, search with git log --grep for the original SHA recorded by cherry-pick -x.

62. A repository has grown to several gigabytes. How do you investigate?

Run git count-objects -vH for size, list the largest blobs with git rev-list --objects --all piped to git cat-file --batch-check, or use git filter-repo --analyze. Move large binaries to LFS, rewrite history if agreed, then repack with git gc --aggressive --prune=now on a fresh clone.

How to prepare for an advanced Git interview

  • Create a test repository and inspect objects with cat-file before and after a commit, merge and rebase.
  • Delete a branch and recover it from the reflog, then run git fsck --lost-found.
  • Rewrite a sample history with filter-repo and confirm the file is gone with git log --all -- path.
  • Clone a large public repository with partial clone and sparse checkout and compare times.
  • Set up SSH commit signing and see the verified badge on your hosting platform.

For related practice, see our guides on Git branching strategies and Git repository management, and the Git branching and merging interview questions. Our DevOps training in Pune uses these Git workflows inside CI/CD and GitOps labs, in the Kharadi classroom or live online.

Frequently asked questions

What counts as an advanced Git interview question?

Questions on Git internals, reflog recovery, interactive rebase, merge strategies, history rewriting, large-repository performance, commit signing and server-side policy, rather than basic add, commit and push.

How do I recover a commit after git reset --hard?

Find the previous position in git reflog and reset back to it, for example git reset --hard HEAD@{1}. Uncommitted changes are not recorded in the reflog.

What is the default merge strategy in Git?

ort, which replaced recursive as the default for merging two heads in Git 2.34.

Should I use git filter-branch or git filter-repo?

Use git filter-repo. The Git documentation warns about filter-branch's pitfalls and performance and points to filter-repo instead.

What is the difference between partial clone and shallow clone?

A shallow clone drops older history. A partial clone keeps full history but downloads file contents only when they are needed.

Can Git sign commits with SSH keys?

Yes. Since Git 2.34 you can set gpg.format to ssh and sign commits and tags with an SSH key.

How many questions are on this page?

62 numbered questions: 14 foundations, 22 for two to five years of experience, 14 senior questions and 12 scenarios.

Official references

Interested in learning more?Get a callback from our training advisors.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.