Q: A developer reports that `git push` is extremely slow (takes 5+ minutes) even for small commits. The repo itself is only 500 MB. How do you diagnose and fix this?
Slow pushes with small changesets typically aren't about bandwidth — the bottleneck is usually pack negotiation or server-side processing.
Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "When an engineer accidentally creates this branch or commit divergence, I walk them through safe recovery without data loss. The interviewer is testing: Debugging Git performance, understanding pack negotiation, and server-side issues.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Initial Diagnostics & Root Cause Analysis
Slow pushes with small changesets typically aren't about bandwidth — the bottleneck is usually pack negotiation or server-side processing.
- Enable Git tracing:
- Check where time is spent:
- "Counting objects" / "Compressing objects" takes minutes? — the local repo has too many loose objects or a bloated object database. Run
git gcandgit repack -a -d --depth=250 --window=250. - Negotiation phase is slow? — Git exchanges "have/want" lists with the server. With many branches and tags, this can be large. Prune stale remote refs:
git remote prune origin. Delete merged branches. - Server-side hooks are slow? — pre-receive or update hooks (code scanning, large file checks, CI triggers) run synchronously. Check with the platform admin.
- Network latency? —
curl -o /dev/null -w "time_connect: %{time_connect}\ntime_total: %{time_total}\n"to check. - Check for large files in recent commits:
Remediation & Permanent Safeguards
Diagnosis: This shows every step: DNS resolution, TLS handshake, ref advertisement, pack negotiation, and upload. A single large blob forces a big packfile upload. Fixes: If the root cause is many stale refs, regularly run git fetch --prune and delete merged feature branches both locally and remotely.
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main
- Run
git gc --aggressiveif the local object store is fragmented. - Enable
push.negotiate(Git 2.36+):git config push.negotiate true— uses a more efficient negotiation algorithm. - Use SSH instead of HTTPS if TLS overhead is contributing.
- Push only the branch you need:
git push origin maininstead ofgit push --all. - Consider
--thin(default) — verify it's not disabled. Thin packs send deltas against objects the server already has, reducing transfer size. - Check for server-side quotas or throttling — some Git hosting providers rate-limit pushes or run expensive server-side operations.
- Enable Git tracing:
- Check where time is spent:
- "Counting objects" / "Compressing objects" takes minutes? — the local repo has too many loose obj...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring developer reports push
git push --forceunconditionally overwrites remote commits made by teammates, whereas--force-with-leaseaborts if the remote ref was updated. - Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring developer reports push Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
-
Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring developer reports push
git reflogtracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches. - Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring developer reports push Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.