The git describe --broken command reports a broken worktree when Git cannot determine if local modifications exist due to repository corruption, broken submodules, or index issues.
The --broken flag in git describe is designed to handle situations where Git cannot reliably determine the state of your working tree. Introduced in Git 2.13, this flag prevents fatal errors when the repository is in a corrupted state or when submodules are broken. When git describe --dirty would normally crash trying to check for modifications, git describe --broken instead appends "-broken" to the output, allowing you to retrieve version information even from a damaged repository. This error typically manifests when Git encounters severe issues: corrupted repository objects, broken or missing submodule references, or an index file that cannot be properly read. The command spawns a child process to check for dirtiness, and if that process dies unexpectedly, Git knows something is fundamentally wrong with the repository state. Understanding this distinction is crucial: --dirty detects uncommitted changes in a healthy repository, while --broken detects when Git itself cannot determine the repository health status.
Run Git's filesystem check to identify any corrupted objects or broken references:
git fsck --fullThis will report any dangling commits, broken links, or corrupted objects. Look for messages starting with "error:" or "fatal:". If fsck completes without errors, the corruption may be in the index or worktree configuration rather than the object database.
Stale index files are a common cause, especially in older Git versions. Refresh it manually:
git update-index --refreshThen try your git describe command again. This forces Git to re-scan the working directory and update its internal state cache.
If you're using submodules, verify their integrity:
git submodule status
git submodule update --init --recursiveBroken submodules are one of the primary reasons git describe --broken was introduced. If submodules show errors, reinitialize them or repair their .git references.
If using linked worktrees and the main repository has moved, repair the connections:
git worktree repairThis reestablishes links between the main worktree and any linked worktrees that may have become disconnected.
Files marked with --assume-unchanged can interfere with state detection. List and clear them:
# List files with assume-unchanged flag
git ls-files -v | grep "^h"
# Clear the flag for specific files
git update-index --no-assume-unchanged path/to/fileRepeat for all affected files, then retry git describe.
If fsck revealed corrupted objects, attempt recovery:
# Create backup first
cp -r .git .git.backup
# Try automatic repair
git reflog expire --expire=now --all
git gc --prune=now --aggressiveFor more severe corruption, you may need to clone fresh from a remote and reapply local changes. Always backup before attempting deep repairs.
The --broken flag was specifically designed for CI/CD environments where you need version information even when repository integrity is questionable. In automated builds, failing fast with git describe --dirty can break pipelines unnecessarily, while git describe --broken --dirty allows the build to continue while flagging the issue.
For scripts that need to detect both dirty and broken states across submodules, use: git describe --broken --dirty --all combined with git submodule foreach. This provides comprehensive state detection across your entire repository tree.
In Git 2.41 and later, sparse-index support improves performance of git describe --dirty in large repositories. If you're working with monorepos or partial checkouts, ensure you're using a recent Git version.
The child process approach used by --broken means it's slightly slower than --dirty alone, but the tradeoff is resilience against repository corruption. In performance-critical scripts, only use --broken when you suspect repository integrity issues.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git