/errors/git/not-a-git-repository
fatal: not a git repository (or any of the parent directories): .git
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
- tool
- Git
- exit code
- 128
- versions
- Git 2.x
- os
- linux, macos, windows
Git prints fatal: not a git repository (or any of the parent directories): .git and exits with status 128 when it cannot find a .git directory in the current folder or any folder above it. Run the command from inside the repository, or create one with git init.
Reproduce the error
mkdir not-a-repo && cd not-a-repo
git statusOutput · exit 128
fatal: not a git repository (or any of the parent directories): .git
Check where you are
git init -q -b main project
cd project && mkdir -p src/deep && cd src/deep
git rev-parse --is-inside-work-tree
git rev-parse --show-toplevel | sed 's|.*/||'Output
true project
Inside any subfolder, Git walks up until it finds .git; --show-toplevel prints that root (the last path segment is shown here).
Fix
- Wrong folder:
cdinto the project, then run the command again. - No history yet:
git init, thengit addandgit commit. - Code from a ZIP download: the archive has no
.git. Usegit clone <url>instead. - Environment overrides:
GIT_DIRandGIT_WORK_TREEtake precedence over the folder search.unset GIT_DIR GIT_WORK_TREEif they are set by mistake.
FAQ
How do I check whether I am inside a repository?
git rev-parse --is-inside-work-tree prints true inside a work tree and fails with exit status 128 outside one. git rev-parse --show-toplevel prints the repository root.
Sources
Related pages
errors · gitfatal: refusing to merge unrelated historiesGit refuses to merge two branches that share no common commit, for example a new local repo and a remote created with a README. Use --allow-unrelated-histories.codes · gitGit exit codes: 0, 1, 128 and 129Git exits with 0 on success, 1 for an ordinary failure or a diff with changes, 128 for fatal errors such as not a git repository, and 129 for invalid usage.cheat sheets · gitGit cheat sheet: everyday commandsGit cheat sheet: setup, stage and commit, branches with switch, history, undo with restore, reset and revert, stash, remotes, tags and the reflog on one page.