Fix: fatal: not a git repository
Git looked in the current directory and every parent for a .git folder and found none. You are in the wrong directory, the project was downloaded as a zip instead of cloned, or .git is missing or damaged.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any parent up to mount point /home)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
Every git command needs a repository. Git searches for a .git directory starting where you are and walking upward through the parents; if it reaches the root (or a mount point) without finding one, it stops with this message.
Cause 1: you are in the wrong directory
pwd
ls -la # is there a .git here?
git rev-parse --show-toplevel 2>/dev/null || echo "not inside a repo"
cd ~/projects/myapp # go to the project folder, then retry
Editors and terminals that open in your home directory, a fresh SSH session, or a cd in a script that did not run are the usual culprits. In a script, cd "$(dirname "$0")" or git -C /path/to/repo status makes the location explicit.
Cause 2: the code was downloaded, not cloned
A zip export from GitHub, a release tarball, or a folder copied from a colleague without .git contains the files but no history. Either clone it properly or start a fresh repository on top.
# Proper clone
git clone https://github.com/owner/repo.git
# Or turn the folder into a new repository
cd myapp
git init
git add .
git commit -m "Import"
Cause 3: .git was deleted or is damaged
rm -rf .git, a cleanup script, a sync tool that skips hidden folders, or a disk problem can remove or corrupt it. If .git exists but git still complains, look inside: .git/HEAD must exist and contain ref: refs/heads/... or a commit hash.
ls .git
cat .git/HEAD
git fsck
A missing HEAD can be recreated with echo 'ref: refs/heads/main' > .git/HEAD (use your real branch name). If the repository is otherwise ruined, re-clone it and copy your uncommitted changes across; the remote still has every pushed commit.
Cause 4: a mount point or container boundary
Git stops at file system boundaries. In a container with the project bind-mounted at a subdirectory, or with a home directory on NFS, the .git above the boundary is not found. Set GIT_DISCOVERY_ACROSS_FILESYSTEM=1, or mount the repository root rather than a subfolder.
Check that it is fixed
git status
git rev-parse --show-toplevel # prints the repository root
When it is not what you think
fatal: detected dubious ownership in repositoryis a different safety check: the repo belongs to another user. Fix withgit config --global --add safe.directory /path/to/repoif you trust it.- In CI, a job that fails with this message usually means the checkout step did not run or ran in another working directory; check the pipeline’s
working-directorysetting. - A
.gitfile (not directory) is normal in worktrees and submodules; it containsgitdir: ...pointing elsewhere. If that path no longer exists, the message appears; fix it withgit worktree repairor re-initialize the submodule withgit submodule update --init.
Official documentation
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0032 First-time Git setup: name, email, default branch, SSH or HTTPS Tell Git who you are, pick sensible defaults, and choose between SSH and HTTPS for GitHub. Includes a small script that applies… Beginner · Step by step · Linux, macOS, Windows Script Setup 15 Oct 2026
- 0033 The everyday Git workflow: status, add, commit, push, pull Git moves your changes through three places: the working folder, the staging area, and the commit history. These five commands, plus .gitignore… Beginner · Explains an idea · Any system Article Housekeeping · Setup 15 Oct 2026
- 0040 Fix: error: failed to push some refs to … Git refused your push, usually because the remote branch has commits you do not have yet. Bring them in, combine them with… Beginner · Fixes an error · Any system Article Common errors 15 Oct 2026
- 0041 Fix: CONFLICT (content): Merge conflict in … Two branches changed the same lines and Git cannot choose for you. Open the file, keep the right text, remove the markers,… Intermediate · Fixes an error · Any system Article Branching & rebasing · Common errors 15 Oct 2026
- 0042 Fix: fatal: refusing to merge unrelated histories Your local repository and the remote do not share a single commit, usually because both were started separately. Allow the one-time merge,… Intermediate · Fixes an error · Any system Article Common errors 15 Oct 2026
- 0262 Make your first pull request: Git and GitHub from first commit to merged change A complete beginner's path through Git and GitHub: set up Git, make commits, ignore files, use branches, push to GitHub, open a… Beginner · Guided project · Any system Article Branching & rebasing · Pull requests · Setup 15 Oct 2026
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +3,070 chars