# git "fatal: not a git repository" in a CI step

> Fix git "fatal: not a git repository (or any of the parent directories): .git" in CI - a git command ran in a directory that was never checked out or is not the repo root.

Source: https://latchkey.dev/learn/git/gcs-checkout-not-a-git-repository-in-ci  
Updated: 2026-06-30

git walked up from the current directory and found no `.git`, so the step is not inside a git working tree. Either actions/checkout never ran before this step, or the step runs in a different directory than the checkout.

## Diagnose it: depth, refs, or credentials?

```Terminal
git rev-parse --is-shallow-repository
git rev-parse --abbrev-ref HEAD    # prints HEAD when detached
git log --oneline -3
git remote -v
```

> `actions/checkout` fetches depth 1 on a detached HEAD. Anything diffing against a base, reading a branch name, or running `git describe` needs `fetch-depth: 0`.

## FAQ

### What causes git "fatal: not a git repository" in a CI step?

There are 2 common causes: the step runs before actions/checkout and the working directory is not the checkout path. Any git command placed before the checkout step runs in an empty workspace with no .git.

### How do I fix git "fatal: not a git repository" in a CI step?

There are 2 fixes depending on which cause you have: check out the repo before git commands and run git in the checkout directory. Work through them in order, since the first is the most common.

### What does git "fatal: not a git repository" in a CI step actually mean?

A git command fails with "fatal: not a git repository (or any of the parent directories): .git", often in a step that runs git log, git describe, or git rev-parse before or outside the checkout.

### How do I stop git "fatal: not a git repository" in a CI step happening again?

Order checkout before any git-using step. The prevention section lists 3 changes that keep it from recurring.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
