crewAIInc/crewAI · error · SystemExit

Unable to validate git state: {exc} Fix the issue or pass --

Error message

Unable to validate git state: {exc}
Fix the issue or pass --force to skip this check.

What it means

While validating pre-publish git state, constructing `git.Repository(fetch=False)` raised a `ValueError` whose message is NOT the expected 'not a Git repository' sentinel. The CLI treats unknown git-layer failures (corrupt refs, unreadable .git, bad git binary) as blocking and suggests `--force`, which skips git validation entirely.

Source

Thrown at lib/cli/src/crewai_cli/skills/main.py:204

        """
        skill_md = Path("SKILL.md")
        if not skill_md.exists():
            console.print(
                "[red]No SKILL.md found in current directory. "
                "Run this command from inside a skill directory.[/red]"
            )
            raise SystemExit(1)

        if not force:
            try:
                repository = git.Repository(fetch=False)
            except ValueError as exc:
                if "not a Git repository" not in str(exc):
                    console.print(
                        f"[red]Unable to validate git state: {exc}\n"
                        "Fix the issue or pass --force to skip this check.[/red]"
                    )
                    raise SystemExit(1) from exc
                # Standalone skill directories may live outside any git repo;
                # there is no git state to validate in that case.
                repository = None
            if repository is not None:
                try:
                    # Refresh remote-tracking refs so is_synced() compares
                    # against the actual remote, not stale local state.
                    repository.fetch()
                except ValueError as exc:
                    console.print(
                        f"[red]Unable to validate git state: {exc}\n"
                        "Fix the issue or pass --force to skip this check.[/red]"
                    )
                    raise SystemExit(1) from exc
            if repository is not None and not repository.is_synced():
                console.print(
                    "[bold red]Failed to publish skill.[/bold red]\n"
                    "Local changes need to be resolved before publishing. Please do the following:\n"

View on GitHub (pinned to 754d7323be)

Solutions

  1. Fix the underlying git problem first (e.g. `git status` in the directory to see the real error; repair permissions with `chown -R $(whoami) .git` or re-clone).
  2. If git state is genuinely irrelevant for this publish, bypass validation with `crewai skill publish --force`.
  3. Update the crewai CLI in case the git wrapper's error handling changed between versions.

Example fix

# before
crewai skill publish   # Unable to validate git state: ...

# after
git status   # diagnose/repair the repo first
crewai skill publish --force   # or skip the check deliberately
Defensive patterns

Strategy: try-catch

Validate before calling

import subprocess

def git_repo_healthy() -> bool:
    return subprocess.run(
        ["git", "status"], capture_output=True
    ).returncode == 0

Try / catch

try:
    publish(force=False)
except SystemExit as e:
    if "Unable to validate git state" in last_message:
        repair_git_or_retry_with_force()
    else:
        raise

Prevention

When it happens

Trigger: Running `crewai skill publish` without `--force` in a directory where `git.Repository()` throws for a reason other than 'not a Git repository' — e.g. a corrupt `.git` directory, permission errors on `.git/refs`, a git worktree with a missing main repo, or an incompatible git version.

Common situations: Damaged or partially-cloned repos; `.git` owned by another user (root-created files after docker use); exotic worktree/submodule setups the git wrapper does not handle; the original exception text from the underlying git library varying by version.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/5627b047f26bc514. Report an issue: GitHub.