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.
fatal: not a git repository (or any of the parent directories): .gitCommon 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.
- uses: actions/checkout@v4
- run: git rev-parse --show-toplevel # confirms you are inside the repoRun from the right directory
- Print
pwdandls -lato confirm a.gitdirectory is present. - Set the step
working-directoryto the checkout path if it differs. - For container steps, mount the workspace so the repo is visible inside.
How to prevent it
- Always run
actions/checkoutbefore steps that invoke Git. - Set
working-directoryexplicitly when the repo is not at the job root. - Mount the workspace into container actions that run Git.