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.
fatal: not a git repository (or any of the parent directories): .gitCommon 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.
steps:
- uses: actions/checkout@v4
- run: git rev-parse HEADRun git in the checkout directory
- Set
working-directoryto the path checkout wrote to. - In containers, ensure the workspace is mounted where the step runs.
- Verify with
git rev-parse --is-inside-work-treebefore other git calls.
git rev-parse --is-inside-work-treeHow 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-treein reusable scripts.