GitHub Actions "fatal: not a git repository" after checkout path
git commands only work inside a checked-out worktree. When actions/checkout used a custom path, or no checkout ran in the job, the working directory has no .git and every git call fails.
What this error means
A git status, git describe, or git rev-parse step fails with "fatal: not a git repository" even though an earlier job checked out the code.
github-actions
fatal: not a git repository (or any of the parent directories): .gitCommon causes
No checkout in this job
Each job starts on a clean runner; a job that never runs actions/checkout has no repository on disk.
checkout used a non-default path
With path: set, the repo lives in a subdirectory, so git run from the default working-directory finds no .git.
How to fix it
Check out the repo where git runs
- Add actions/checkout to every job that needs the repository.
- If you set a custom path, run git steps with working-directory pointing at it.
- Do not assume artifacts or files persist across jobs without a checkout.
.github/workflows/ci.yml
- uses: actions/checkout@v4
with:
path: src
- run: git rev-parse HEAD
working-directory: srcHow to prevent it
- Add a checkout to each job that touches git.
- Keep working-directory aligned with the checkout path input.
Related guides
actions/checkout: Inputs & Workflow UsageReference for actions/checkout: clone your repository into the runner, control fetch-depth, submodules, refs,…
GitHub Actions checkout "fatal: could not read Username" (submodules)Fix actions/checkout "fatal: could not read Username for https://github.com" on submodules - the default toke…
GitHub Actions checkout "couldn't find remote ref"Fix actions/checkout "couldn't find remote ref" - the ref input points at a branch, tag, or SHA that does not…