Skip to content
Latchkey

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

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.

Related guides

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