Skip to content
Latchkey

Git "fatal: not a git repository" in CI

Git could not find a .git directory in the current path or any parent. The step is running outside a checked-out repository - either before checkout ran, or from the wrong working directory.

What this error means

Any Git command fails with fatal: not a git repository (or any of the parent directories): .git. The rest of the job may work; only Git-dependent steps fail because there is no repo where they run.

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

Common causes

Git ran before checkout

A step that calls Git executes before actions/checkout (or the clone) has populated the workspace, so there is no .git yet.

Wrong working directory

The command runs in a directory outside the checkout - a different working-directory, a container with a different mount, or a path the clone did not target.

A container step without the repo mounted

A container action that does not mount the workspace sees an empty filesystem, so Git finds no repository.

How to fix it

Check out the repo before any Git step

Ensure actions/checkout runs first and that Git steps run inside the checkout path.

.github/workflows/ci.yml
- uses: actions/checkout@v4
- run: git rev-parse --show-toplevel   # confirms you are inside the repo

Run from the right directory

  1. Print pwd and ls -la to confirm a .git directory is present.
  2. Set the step working-directory to the checkout path if it differs.
  3. For container steps, mount the workspace so the repo is visible inside.

How to prevent it

  • Always run actions/checkout before steps that invoke Git.
  • Set working-directory explicitly when the repo is not at the job root.
  • Mount the workspace into container actions that run Git.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →