Skip to main content
Git & Version Control · Developer Error Resolution Lab

Fix 'fatal: not a git repository (or any of the parent directories): .git'

Run Git from the right folder, initialize a repository, or repair a missing/corrupted .git directory and safe.directory ownership checks.

Triggered Error Message:

fatal: not a git repository (or any of the parent directories): .git

Customize Solution for Your Environment
# Option A: you are in the wrong folder
cd /path/to/your/project && git status

# Option B: initialize and connect to the remote
git init
git remote add origin git@github.com:user/repo.git
git fetch origin
git checkout -b main --track origin/main

# Option C: CI / Docker - make sure the checkout step runs (actions/checkout@v4)
# and that .git is not excluded by .dockerignore

Root Cause & Mechanism Analysis

Why does this error occur?

Git searches the current directory and its parents for a `.git` folder. The error means you are outside the project folder, the repository was never initialized, the `.git` directory was deleted, or (in CI/Docker) the checkout step did not run.

Frequently Asked Questions

Why does this happen inside a Docker build?
`.git` is usually listed in `.dockerignore`, so it is not copied into the image. Pass the commit SHA as a build arg instead of running git inside the build.
DEVSECOPS & CI/CD PARTNER2 Slots Open

Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?

Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.

Browse All 69 Guides