Cause 1 of 5
You are in the wrong directory.
pwd to see where you are and ls -a to look for a .git entry. The repository is whichever folder contains it; cd there. This is by far the most common cause and costs nothing to check first.
Git · 5 common causes
Updated
The directory you ran the command in — and none of its parents — contains a Git repository.
$ git status
fatal: not a git repository (or any of the parent directories): .gitPaths, line numbers and stack frames differ on every machine, and the wording is tightened between versions. The part that identifies the problem is fatal: not a git repository.
Cause 1 of 5
pwd to see where you are and ls -a to look for a .git entry. The repository is whichever folder contains it; cd there. This is by far the most common cause and costs nothing to check first.
Cause 2 of 5
git init if it is genuinely new. If it should already be a clone, you probably downloaded a ZIP of the code — a ZIP contains no history, so clone the repository instead.
Cause 3 of 5
git clone <url> creates a subdirectory named after the repository. cd project and the same command will work.
Cause 4 of 5
In a submodule or a linked worktree, .git is a file containing a gitdir: line rather than a directory. Read it with cat .git; if that path is gone, run git submodule update --init from the parent repository to restore the link.
Cause 5 of 5
Some pipelines skip the checkout for cached jobs, and some Docker builds copy source without the .git directory — which is often deliberate, since it keeps history out of the image. Move the Git command to a stage that has the repository, or pass the value it needed (a commit SHA, a version) in as a build argument.
Show the current Git branch in your shell prompt: it disappears the moment you step outside a repository, which makes this error obvious before you run the command.
Reproducing the failure in a scratch file is usually faster than editing the real one. AltF Code is a free in-browser editor with real syntax highlighting for HTML, CSS, JavaScript, TypeScript, Python, SQL and JSON, and it runs HTML, CSS and JavaScript live in a preview panel. No install and no sign-up.
Open the editor