Skip to content
LatchkeyLatchkey home

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

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.

What this error means

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.

git
fatal: not a git repository (or any of the parent directories): .git

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

Common causes

The step runs before actions/checkout

Any git command placed before the checkout step runs in an empty workspace with no .git.

The working directory is not the checkout path

A different working-directory, a container without the checkout mounted, or a path set to . where nothing was cloned has no repo.

How to fix it

Check out the repo before git commands

Ensure actions/checkout runs first so a .git exists.

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
  - run: git rev-parse HEAD

Run git in the checkout directory

  1. Set working-directory to the path checkout wrote to.
  2. In containers, ensure the workspace is mounted where the step runs.
  3. Verify with git rev-parse --is-inside-work-tree before other git calls.
Terminal
git rev-parse --is-inside-work-tree

How to prevent it

  • Order checkout before any git-using step.
  • Keep git steps in the directory checkout populated.
  • Guard with git rev-parse --is-inside-work-tree in reusable scripts.

Frequently asked questions

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.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card