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.
fatal: not a git repository (or any of the parent directories): .git
# 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?
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.
Related Developer Error Solutions
Browse All 69 GuidesGit: error: failed to push some refs to origin
Resolve rejected pushes caused by remote commits you do not have locally, protected branches, or secret-scanning push protection.
Git: Detached HEAD State
Safely create a new branch from a detached HEAD or return to your main branch without losing commits.
Git: Refusing to merge unrelated histories
Merge repositories initialized independently with different initial commits using --allow-unrelated-histories.