Chaturmind
LearnDSASystem DesignInterview PrepDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth
  • Java Interview Prep

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Java Interview Prep: 2–5 Years

Revise the Fresher Tier

  • Revise: Core Java Fundamentals (Fresher Tier)
  • Revise: Collections, Threads, Java 8 & Coding (Fresher Tier)
  • Revise: Spring Core, Spring Boot & Spring MVC (Fresher Tier)
  • Revise: Hibernate, SQL, Microservices, Maven & Git (Fresher Tier)

Intermediate Core Java

  • Intermediate OOP & Language Features — Interview Questions
  • Enums, Generics, Pass-by-Value & Imports — Interview Questions
  • Collections Internals & Scenarios — Interview Questions
  • JVM, Memory & Class Loading — Interview Questions
  • Exception Design & Serialization Edge Cases — Interview Questions

Java 8 Deep Dive & Stream Coding

  • Lambdas, Functional Interfaces & Method References — Interview Questions
  • Default Methods, Backward Compatibility & Optional — Interview Questions
  • Stream API Internals (Part 1) — Interview Questions
  • Stream API Internals (Part 2) — Interview Questions
  • Stream Coding Problems (Level 2, Part 1) — Interview Questions
  • Stream Coding Problems (Level 2, Part 2) — Interview Questions

Concurrency & Multithreading

  • Synchronization, Locks & Deadlocks — Interview Questions
  • Executors, ThreadLocal & Concurrent Collections — Interview Questions

Spring Framework In Depth

  • Bean Lifecycle, Contexts & Circular Dependencies — Interview Questions
  • Spring Bean Conflicts, AOP, Batch & Injection Styles — Interview Questions

Spring Boot In Depth & Scenarios

  • Spring Boot Internals & Auto-Configuration — Interview Questions
  • Spring Boot Configuration, Profiles & Secrets — Interview Questions
  • Spring Boot Data, Transactions & Caching — Interview Questions
  • Spring Boot Testing, Error Pages & Deployment — Interview Questions
  • Spring Boot Performance, Scaling & Resilience — Interview Questions
  • Spring Boot Async, Events & Messaging — Interview Questions
  • Spring Boot Security Scenarios — Interview Questions
  • Actuator, AOP, Spring Cloud & Distributed Tracing — Interview Questions
  • External APIs, Files, GraphQL & WebFlux — Interview Questions

Spring Security

  • Spring Security — OAuth2, CORS, CSRF & Access Rules — Interview Questions
  • Spring Security — Passwords, Filter Chain, Sessions & Debugging — Interview Questions

Apache Kafka

  • Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions
  • Kafka Producers, Consumers, Reliability & Streams — Interview Questions
  • Kafka Security, Connect & Core Scenarios — Interview Questions
  • Kafka Production Scenarios — Interview Questions

Git, Maven & Gradle (Level II)

  • Git Workflows, Rebase & Conflict Handling — Interview Questions
  • Git Recovery, Hooks, Tags & Collaboration — Interview Questions
  • Maven Builds, Multi-Module Projects & Dependency Resolution — Interview Questions
  • Maven Profiles, settings.xml, Plugins & Quality Gates — Interview Questions
  • Gradle Fundamentals, Migration & Dependencies — Interview Questions
  • Gradle Performance, Plugins, Testing & Publishing — Interview Questions

Deployment & CI/CD

  • Sessions, CI/CD Pipelines, Rollbacks & Secrets — Interview Questions
  • Migrations, Zero-Downtime Releases, Containers & Monitoring — Interview Questions

JUnit 5 & Mockito

  • JUnit 5 — Interview Questions
  • Mockito Basics — Interview Questions
  • Mockito Advanced & Tricky Questions — Interview Questions
Chaturmind
← Java Interview Prep: 2–5 Years

Revise the Fresher Tier

  • Revise: Core Java Fundamentals (Fresher Tier)
  • Revise: Collections, Threads, Java 8 & Coding (Fresher Tier)
  • Revise: Spring Core, Spring Boot & Spring MVC (Fresher Tier)
  • Revise: Hibernate, SQL, Microservices, Maven & Git (Fresher Tier)

Intermediate Core Java

  • Intermediate OOP & Language Features — Interview Questions
  • Enums, Generics, Pass-by-Value & Imports — Interview Questions
  • Collections Internals & Scenarios — Interview Questions
  • JVM, Memory & Class Loading — Interview Questions
  • Exception Design & Serialization Edge Cases — Interview Questions

Java 8 Deep Dive & Stream Coding

  • Lambdas, Functional Interfaces & Method References — Interview Questions
  • Default Methods, Backward Compatibility & Optional — Interview Questions
  • Stream API Internals (Part 1) — Interview Questions
  • Stream API Internals (Part 2) — Interview Questions
  • Stream Coding Problems (Level 2, Part 1) — Interview Questions
  • Stream Coding Problems (Level 2, Part 2) — Interview Questions

Concurrency & Multithreading

  • Synchronization, Locks & Deadlocks — Interview Questions
  • Executors, ThreadLocal & Concurrent Collections — Interview Questions

Spring Framework In Depth

  • Bean Lifecycle, Contexts & Circular Dependencies — Interview Questions
  • Spring Bean Conflicts, AOP, Batch & Injection Styles — Interview Questions

Spring Boot In Depth & Scenarios

  • Spring Boot Internals & Auto-Configuration — Interview Questions
  • Spring Boot Configuration, Profiles & Secrets — Interview Questions
  • Spring Boot Data, Transactions & Caching — Interview Questions
  • Spring Boot Testing, Error Pages & Deployment — Interview Questions
  • Spring Boot Performance, Scaling & Resilience — Interview Questions
  • Spring Boot Async, Events & Messaging — Interview Questions
  • Spring Boot Security Scenarios — Interview Questions
  • Actuator, AOP, Spring Cloud & Distributed Tracing — Interview Questions
  • External APIs, Files, GraphQL & WebFlux — Interview Questions

Spring Security

  • Spring Security — OAuth2, CORS, CSRF & Access Rules — Interview Questions
  • Spring Security — Passwords, Filter Chain, Sessions & Debugging — Interview Questions

Apache Kafka

  • Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions
  • Kafka Producers, Consumers, Reliability & Streams — Interview Questions
  • Kafka Security, Connect & Core Scenarios — Interview Questions
  • Kafka Production Scenarios — Interview Questions

Git, Maven & Gradle (Level II)

  • Git Workflows, Rebase & Conflict Handling — Interview Questions
  • Git Recovery, Hooks, Tags & Collaboration — Interview Questions
  • Maven Builds, Multi-Module Projects & Dependency Resolution — Interview Questions
  • Maven Profiles, settings.xml, Plugins & Quality Gates — Interview Questions
  • Gradle Fundamentals, Migration & Dependencies — Interview Questions
  • Gradle Performance, Plugins, Testing & Publishing — Interview Questions

Deployment & CI/CD

  • Sessions, CI/CD Pipelines, Rollbacks & Secrets — Interview Questions
  • Migrations, Zero-Downtime Releases, Containers & Monitoring — Interview Questions

JUnit 5 & Mockito

  • JUnit 5 — Interview Questions
  • Mockito Basics — Interview Questions
  • Mockito Advanced & Tricky Questions — Interview Questions
HomeLearnJava Interview PrepJava Interview Prep: 2–5 YearsGit, Maven & Gradle (Level II)
✓ FreeIntermediate· 8 min read

Git Recovery, Hooks, Tags & Collaboration — Interview Questions

Handling committed secrets (rotate first, then rewrite), Git hooks in teams, getting an old version of a file without losing work, tracking others' changes correctly, a complicated multi-file conflict, tags and releases, a teammate breaking the build, detached HEAD, feature toggles vs branches, and sharing work without merging.

Published September 25, 2026


How to use this lesson

Several widely shared answers to these questions are wrong in ways that cause real damage: rewriting history before rotating a leaked secret, a git log command that shows the opposite of what's claimed, "feature toggles with branches". Give the correct version, and briefly say why.

Q1. You accidentally committed sensitive information, such as a password. What do you do?

Short answer: In this order:

  1. Rotate or revoke the secret immediately. Assume it's compromised the moment it was pushed. Bots scan public repositories within minutes, and forks, clones and CI caches may already hold it.
  2. Remove it from the code going forward: move it to environment variables or a secrets manager, and add the file to .gitignore.
  3. Purge it from history, if the policy requires it: git filter-repo or the BFG Repo-Cleaner (git filter-branch is deprecated), then force-push, coordinate with the team to re-clone, and ask the hosting provider to purge cached views.
  4. Add prevention: pre-commit secret scanning (gitleaks), and push protection or secret scanning on GitHub or GitLab.

Common trap: starting with "rewrite history and force-push". History rewriting doesn't un-leak a secret. Rotation is the actual fix.

Q2. How can Git hooks improve a team's workflow?

Short answer: Hooks are scripts that Git runs at points in its workflow:

  • Client-side: pre-commit (format, lint, scan for secrets), commit-msg (enforce message conventions), pre-push (run fast tests).
  • Server-side: pre-receive, update (reject pushes that break policy).

They catch problems before they reach review or CI.

Key points to cover:

  • Client hooks live in .git/hooks, and aren't shared automatically. Distribute them with tools such as pre-commit (the framework), Husky, or core.hooksPath pointing to a versioned folder.
  • They can be bypassed (--no-verify), so enforce the important rules in CI, and in server-side branch protection too.
  • Keep hooks fast. Slow hooks get disabled.

Q3. You've changed a file a lot, and want an earlier version of it without losing your current work. How?

Short answer: View or extract the old version, without touching your working copy:

git show <commit>:src/main/java/com/shop/Pricing.java > /tmp/Pricing.old.java   # a copy to compare
git diff <commit> -- src/main/java/com/shop/Pricing.java                         # what changed since then
git restore --source=<commit> --worktree -- Pricing.java    # replace the file… only after committing/stashing your work
git worktree add ../shop-old <commit>                       # a separate checkout of the whole old tree

Key points to cover:

  • To keep both versions safely: first commit (or stash) your current work, then restore the old version, compare, and merge the parts you need.
  • git stash, then check out the old file, then git stash pop (the common answer) usually leads to conflicts or confusion. Extracting the file to a separate path is simpler.

Q4. How can you track changes made by others in a shared repository?

Short answer: Fetch first, then compare your branch with the remote:

git fetch --all --prune
git log --oneline HEAD..origin/main              # commits on the remote that you don't have yet
git log --oneline origin/main..HEAD              # your commits that the remote doesn't have
git diff HEAD...origin/main                      # changes on main since your branch diverged
git log --since="1 week" --author="Asha" -- src/payments/   # who changed what, where

Common trap: git log --branches --not --remotes shows your local commits that haven't been pushed, which is the opposite of "changes made by others".

Key points to cover:

  • Also use the hosting platform: PR activity, CODEOWNERS notifications, and "watch" on critical paths.

Q5. Describe a complicated multi-file merge conflict you resolved.

Short answer (a model story): "Two teams refactored the pricing module in parallel. One renamed classes and moved packages, while the other changed the discount logic, which produced conflicts in 14 files. I first merged the structural rename on its own, so Git could track the moves, then re-applied the logic change. Where I was unsure, I used a three-way merge tool with zdiff3, resolved it with both authors on a call, and ran the full test suite plus contract tests before merging. Afterwards we agreed to do cross-cutting refactors in small, quickly merged PRs."

Key points to cover:

  • A good answer shows method (separate structure from logic, use the right tools), collaboration (talk to the authors) and verification (tests before merging), plus a lesson learned.

Q6. How do you create and manage tags, and when do you use them?

Short answer: Tags mark release points. Use annotated tags for releases: they record the tagger, date and message, and can be signed. Lightweight tags are just pointers.

git tag -a v2.3.0 -m "Release 2.3.0" <commit>     # annotated (add -s to GPG-sign)
git push origin v2.3.0                             # push one tag (or: git push --follow-tags)
git tag -d v2.3.0-rc1 && git push origin :refs/tags/v2.3.0-rc1   # delete locally and remotely

Key points to cover:

  • Use them for release versions (SemVer), so CI builds and deploys the exact tagged commit, and you can reproduce or hotfix from it.
  • Don't move published tags. Consumers expect them to be immutable.
  • git push --tags pushes every local tag, including experimental ones. Push specific tags, or use --follow-tags.

Q7. A teammate pushes a commit that breaks the build. What do you do?

Short answer:

  1. Restore green quickly. If the fix isn't obvious within minutes, git revert the offending commit on main (never force-push main).
  2. Identify the cause from the CI logs, or with git bisect, if it isn't clear which commit did it.
  3. Tell the author, without blame, and let them fix it forward in a new PR.
  4. Prevent recurrence: required CI checks on PRs, branch protection, and merge queues that test the combined result.

Q8. What is a "detached HEAD", and how does it happen?

Short answer: HEAD normally points to a branch, which points to a commit. In a detached HEAD state, HEAD points directly to a commit. It happens when you check out a commit hash, a tag or a remote-tracking ref (git checkout v2.3.0, git checkout origin/main), and during rebases and bisects. You can look around and commit, but new commits belong to no branch, and become unreachable once you switch away. They're recoverable from the reflog for a while.

git switch -c hotfix/v2.3.1        # keep work done in detached HEAD by creating a branch here

Q9. How can Git be used together with feature toggles?

Short answer: Feature toggles (flags) exist precisely so you don't need long-lived feature branches. You merge incomplete features into main continuously, hidden behind a runtime flag, and release them by switching the flag on, which is independent of deploying. Git's role is trunk-based development: small, frequent merges. The flag system (configuration, or a feature-flag service) controls exposure: per environment, per user or by percentage.

if (featureFlags.isEnabled("new-checkout", user)) {
    return newCheckout.place(cart);
}
return legacyCheckout.place(cart);

Common trap: "create a branch for the feature and merge it when it's ready". That's the long-lived-branch workflow feature toggles are designed to replace.

Key points to cover:

  • Clean up flags after launch. Stale flags turn into technical debt.

Q10. You need to share changes from a feature branch with another developer without merging. How?

Short answer: Push the branch, and have them check it out:

git push -u origin feature/export-v2
# teammate:
git fetch origin
git switch feature/export-v2            # creates a local tracking branch

Other options:

  • A draft pull request, for visibility and comments.
  • git format-patch / git am, or git bundle, for offline or air-gapped sharing.

Key points to cover:

  • If you both commit to the branch, agree on who rebases, or just use pull --rebase and avoid force-pushing shared branches.

Follow-up questions this topic invites — and their answers

Q: What's the difference between git revert and git reset? A: revert adds a new commit that undoes an old one, which is safe on shared branches. reset moves the branch pointer back, rewriting history, so use it only for unpublished commits.

Q: What's the difference between a merge commit and a fast-forward? A: If the target branch hasn't moved since you branched, Git just moves its pointer forward (a fast-forward), with no new commit. Otherwise it creates a merge commit with two parents.

Q: How do you sign commits, and why? A: With GPG, SSH or S/MIME keys (git config commit.gpgsign true). Signatures prove the commits came from you. Platforms can require verified signatures on protected branches.

Q: What is a monorepo, and which Git features help at scale? A: A monorepo holds many projects in one repository. At scale, it relies on partial clone (--filter=blob:none), sparse checkout, git maintenance, the commit-graph, and CODEOWNERS, plus build tools that only rebuild what changed.

Previous

Git Workflows, Rebase & Conflict Handling — Interview Questions

Next

Maven Builds, Multi-Module Projects & Dependency Resolution — Interview Questions

AI Tutor

Lesson: Git Recovery, Hooks, Tags & Collaboration — Interview Questions

Quick actions

AI responses can be inaccurate. Verify critical information.