Use it as the entry point when something on Git fails and you need to find the failing layer.
Git Troubleshooting
Git Troubleshooting isolates failures across repository state, refs/history, worktree/index, remote configuration, transport/authentication, server policy and downstream automation without destroying recoverable evidence.
1. Issues: detached HEAD, lost commits (reflog), auth failures, large files, line endings.
2. Reflog recovers most mistakes.
3. Check credentials/SSH keys.
4. git lfs for large files.
5. .gitattributes for line endings.
symptom → git state → reflog/trace → fix
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
git status --short --branchPrimary Commands
Configuration and operational commands for this Topic.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
symptom/command → repository/root/state → HEAD/refs/history → index/worktree → remote/refspec → network/TLS/auth → server policy → minimal repair → original-test/read-back
Healthy evidence: failure is reproducible and localized, recoverability is preserved, the fix is minimal and original local/remote operation plus downstream checks pass.
Step 2 Command read-back and what it shows Verify boundary
Known-good is the intended branch is checked out, working tree/index are in the expected clean or deliberately changed state, upstream divergence is understood, and the original fetch/pull/push workflow completes; broken state is unexpected untracked/modified files, detached HEAD, unresolved conflicts or unexplained ahead/behind state persists and the original Git operation still fails. git status shows local repository state only, but it does not show remote authentication, server policy or that a remote update has been accepted.
Step 3 Common mistakes Verify boundary
- Using
reset --hardwithout checking uncommitted work.
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: random reset/clean/force operations, deleting .git metadata, retrying without evidence, stale remote assumptions or stopping at command exit zero.
Step 5 Observation-driven branch and next-check logic Narrow the fault
If status shows local modifications, preserve or commit/stash them before blaming the remote; if status shows ahead/behind or detached HEAD, inspect refs/upstream; if status shows merge/rebase conflict state, resolve or abort that operation before retrying pull/push.
Step 6 Where it fails Narrow the fault
Where Git Troubleshooting usually goes wrong: immutable commit/object identity, refs/remotes, history mutation and consumer checkout/build binding.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Command error ≠ repository corruption; many failures originate in state, permissions, remote policy or transport.
- Changed symptom ≠ root cause fixed; a retry can succeed after transient conditions without explaining the boundary.
- Reset/clean success ≠ safe recovery; destructive commands can erase the evidence or work that explained the issue.
- Remote rejection ≠ local Git bug; authentication, authorization, protected refs and server hooks are independent boundaries.
git status; git log --oneline -5— stategit reflog— recover lost commitsGIT_TRACE=1 git <cmd>— debug
ReferenceWhat it is1 section · depth on demand
Core model
Reproduce the exact Git operation and error, capture repository/ref state first, locate the first failing step, then make one minimal reversible correction. Use reflog or object evidence carefully before resets, cleans, force pushes or history rewrites.
ReferenceHow it works1 section · depth on demand
How it works
Git Troubleshooting is governed by repository HEAD, index, working tree and configured upstream/ref relationships. Git compares the working tree against the index and HEAD while branch/upstream metadata determines ahead/behind state; merge/rebase operations add temporary state files that alter what commands are valid until the operation is completed or aborted. Filesystem permissions, hooks, remotes, authentication and server-side branch policy are adjacent boundaries. The important state separation is that a clean working tree does not mean the branch is synchronized with its remote, and a fetched remote ref does not mean a merge/rebase can complete without conflicts.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
A Git command succeeding after a change shows only that operation now passed. Root cause is resolved when the first failing step is explained and local/remote state plus downstream effects are verified.
Method
Git troubleshooting starts by reading git status, which usually explains the current state and the next command to run.
1. git status — branch, staged/unstaged changes, ongoing merge/rebase.
2. git log --oneline --graph --all -20 — where branches point.
3. git remote -v and git fetch — remote reachability.
4. git reflog — find lost commits after reset or rebase.
| Problem | Fix |
|---|---|
| Merge conflict | Edit conflicted files, git add, continue |
| Detached HEAD | git switch -c new-branch to keep work |
| Committed to wrong branch | git cherry-pick to the right one, reset the wrong one |
| Lost commit after reset | Find it in git reflog, then branch from it |
| Committed a secret | Rotate it first, then rewrite history |
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Git > Git Troubleshooting. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://git-scm.com/docs · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Git Troubleshooting Git boundary map
Fast local-state, history/ref, remote and downstream proof boundaries for Git Troubleshooting.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Local state | Repository, HEAD, worktree/index and commit IDs are explicit | Wrong repo/ref, hidden staged/untracked state or mutable-name ambiguity |
| History / refs | Ancestry and branch/tag movement match intent | Unexpected rewrite, stale tracking ref or unclear merge base |
| Remote sync | URL/refspec, auth and remote read-back match expected commits | Local assumptions, rejection, stale fetch or unsafe force update |
| Downstream proof | Build/reconciliation/target is verified independently | Push/tag/merge success treated as deployment success |
Deep reference
Healthy vs suspicious evidence
Output interpretation
For Git Troubleshooting, rely on structured fields and stable IDs (immutable commit/object identity, refs/remotes, history mutation and consumer checkout/build binding) rather than text formatted for display.