Fix "fatal: not a git repository (or any of the parent directories): .git"
fatal: not a git repository (or any of the parent directories): .git
- fatal: not a git repository (or any parent up to mount point /)
- Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
- fatal: not a git repository: /home/user/project/.git/worktrees/feature
- fatal: not a git repository: ../.git/modules/lib
Git cannot find a .git folder in the current directory or any of its parents: you are not inside a repository. Move into the project folder (cd my-project), or create the repository with git init or git clone.
What this error means
Almost every Git command (status, add, commit, push…) works on a repository. To find it, Git starts from the current folder and walks up to the root of the disk looking for a .git folder (or a .git file for worktrees and submodules). If it finds none, it stops with this message. The "not a git repository: path" form means something else: a .git exists but points to a folder that no longer exists (deleted worktree, moved submodule) or the GIT_DIR variable targets a wrong path.
Common causes
- Wrong folder: the terminal is open in your home folder or in the parent folder, not in the one created by
git clone. - Repository never initialised: the project was downloaded as a ZIP or created by hand, without
git init. .gitfolder missing: deleted by mistake, not copied (it is hidden), or excluded by.dockerignoreduring a Docker build that callsgit.- Broken worktree or submodule: the
.gitfile containsgitdir: …pointing to a path that no longer exists. GIT_DIRorGIT_WORK_TREEvariable set wrongly in the shell or a script.
Step-by-step fix
-
Check where you are
Print the current folder and its content, hidden files included. In Windows PowerShell, use
Get-LocationandGet-ChildItem -Force.pwd ls -la git rev-parse --show-toplevel -
Move into the repository folder
git clonecreates a subfolder named after the repository: go into it before any other Git command.git clone [email protected]:user/repo.git cd repo git status -
Create the repository if it does not exist
For a project not yet tracked by Git, initialise it at its root, then link it to your remote repository.
cd /path/to/project git init git add . git commit -m "Initial commit" git remote add origin [email protected]:user/repo.git -
Broken worktree or submodule
For a moved worktree,
git worktree repair(run from the main repository) recreates the links andgit worktree prunecleans up deleted ones. For a submodule, re-initialise it from the parent repository.cat .git git worktree repair /path/to/worktree git worktree prune git submodule update --init --recursive -
Check GIT_DIR and GIT_WORK_TREE
If one of these variables is set, Git no longer looks for the repository automatically. Unset them in the current shell, then remove them from your profile or the script that sets them.
env | grep ^GIT_ unset GIT_DIR GIT_WORK_TREE -
In a Docker build or CI
The
.gitfolder is often excluded from the image (and that is better). Instead of callinggitin theDockerfile, pass the value you need as a build argument.docker build --build-arg GIT_SHA=$(git rev-parse --short HEAD) -t myapp . # Dockerfile: # ARG GIT_SHA # ENV GIT_SHA=$GIT_SHA
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Open your editor’s integrated terminal from the project folder: it starts in the right place.
- Show the Git branch in your prompt (Oh My Zsh, Starship, posh-git): you instantly see whether you are in a repository.
- Never delete the
.gitfolder to clean up a project: the whole local history goes with it.
Frequently asked questions
Why can’t I see the .git folder?
It is hidden. Show it with ls -la (macOS, Linux), Get-ChildItem -Force (PowerShell), Cmd+Shift+. in Finder or "Hidden items" in Windows Explorer.
What does "Stopping at filesystem boundary" mean?
Git walked up the folders to another filesystem (mounted drive, Docker volume) without finding a repository and stops there for safety. Move into the repository folder rather than setting GIT_DISCOVERY_ACROSS_FILESYSTEM.
Why does the error appear with composer or npm?
A script or tool (Husky hooks, version computed from Git) runs a git command in a folder that is not a repository. Run the install from the repository root, or initialise it with git init.
Useful tools for this error
More Git & GitHub errors
- Fix "failed to push some refs" (! [rejected] fetch first) in Git
- Fix "fatal: refusing to merge unrelated histories" in Git
- Fix "Permission denied (publickey)" with Git and GitHub
- Get out of "detached HEAD" state in Git without losing commits
- Fix "Your local changes to the following files would be overwritten by merge" in Git
- Resolve "CONFLICT (content): Merge conflict" and "Automatic merge failed" in Git
- Fix "Support for password authentication was removed" on GitHub
- Fix "GH001: Large files detected" (file over 100 MB) on GitHub