Skip to content
Latchkey

GitHub Actions "fatal: not in a git directory" After a Step

A git command ran where there is no repository - usually because the step is before actions/checkout, or runs in a directory other than the checked-out workspace.

What this error means

A step calling git (describe, rev-parse, log) fails with "fatal: not in a git directory" or "not a git repository", even though the repo is checked out elsewhere in the job.

Actions log
fatal: not in a git directory
# or
fatal: not a git repository (or any of the parent directories): .git

Common causes

git ran before checkout

Hosted runners start with an empty workspace. Any git command in a step that runs before actions/checkout has no .git to operate on.

Wrong working directory

A step with a working-directory (or a script that cd-s elsewhere) runs git outside the checked-out repo, so git finds no repository.

How to fix it

Check out before any git step

Make actions/checkout the first step so the repository exists when later steps call git.

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
  - run: git describe --tags --always

Run git inside the repo directory

  1. Drop or correct a working-directory that points outside the checkout.
  2. If the repo is checked out to a custom path, set path: on checkout and cd there before git.
  3. Add git config --global --add safe.directory when the workspace owner differs (common in containers).

How to prevent it

  • Place actions/checkout first in every job that uses git.
  • Keep git commands in the checked-out workspace directory.
  • Mark the workspace as a safe.directory inside container jobs.

Related guides

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