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.
fatal: not in a git directory
# or
fatal: not a git repository (or any of the parent directories): .gitCommon 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.
steps:
- uses: actions/checkout@v4
- run: git describe --tags --alwaysRun git inside the repo directory
- Drop or correct a working-directory that points outside the checkout.
- If the repo is checked out to a custom path, set path: on checkout and cd there before git.
- 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.