fatal: Not a Git Repository Error
Fix 'fatal: not a git repository' errors when running git commands outside a git repository or in a detached work tree.
What Does This Error Mean?
The 'fatal: not a git repository' error means git cannot find a .git directory in the current or parent directory. Git commands must be run inside an initialized git repository.
Common Causes
Running git commands in a directory that is not a git repository
The .git directory was deleted or corrupted
Working in a subdirectory of a repo that has a broken .git file
Git submodule not initialized
The current directory is outside the repository boundaries
Detached work tree without proper GIT_DIR configuration
How to Fix It
Initialize a new repository
Use git init to create a new git repository in the current directory.
# Initialize a new repository git init # Or clone an existing repository git clone https://github.com/user/repo.git cd repo
Find the nearest repository
Check if you are inside a repository and find its root.
# Check if .git exists ls -la .git # Find the root of the current repository git rev-parse --show-toplevel # Move to the repository root cd "$(git rev-parse --show-toplevel)"
Initialize submodules if needed
If working with submodules, they must be initialized.
# Clone repo with submodules git clone --recurse-submodules https://github.com/user/repo.git # Or initialize submodules after cloning git submodule init git submodule update # If submodule .git is a file (not directory), run: git submodule update --init --recursive
Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
401 Unauthorized Error
Learn what a 401 Unauthorized error means, common causes, and how to fix authentication failures in your web applications.
403 Forbidden Error
Learn what 403 Forbidden means, how it differs from 401, and how to fix access denied errors in your applications.
404 Not Found Error
Learn what 404 Not Found means, common causes, and how to fix broken links and missing resources on your website or API.
429 Too Many Requests Error
Learn what 429 Too Many Requests means, how rate limiting works, and how to handle or avoid hitting API rate limits.