THE GITHTML FIELD GUIDE
Fix “not a git repository” by finding the right folder
The “not a git repository” error usually means Git cannot find repository metadata from the current directory. Confirm where your terminal is, locate the actual clone, and check whether your files came from a ZIP instead. Do not run git init reflexively: that can create unrelated history or place a repository around the wrong directory.
Distinguish location from missing history
A terminal opened beside a project is not necessarily inside its repository. Editors can also launch terminals at a workspace parent containing several projects. Navigate to the intended project directory and inspect its contents. If you downloaded a source archive, the absence of .git metadata is expected; an archive supplies files, not the original repository database.
If the folder used to be a clone, consider whether metadata was moved, omitted by a copy operation, or affected by filesystem access. Do not delete hidden files or recreate history while investigating. The visible source can be intact even when the repository context is wrong.
Use explicit read-only location checks
Run pwd to show the shell directory, then use Git’s root and metadata checks from the suspected project folder. A failure is diagnostic output, not an instruction to initialize. If an environment variable points Git elsewhere, inspect the relevant environment through your normal shell tools without dumping unrelated secrets.
- If the project is an archive, keep any edits safe and clone the original into a separate destination when you actually need its history.
- If you find an existing clone elsewhere, compare revisions and local modifications before transferring files; do not overwrite one directory with the other.
pwd
git rev-parse --show-toplevel
git rev-parse --git-dir
git statusRestore the intended context
Once Git reports the expected repository root, rerun the original inspection command. Check the branch and remote to ensure you found the correct project rather than a similarly named clone. Only initialize a new repository when your actual goal is starting new history around previously unversioned files. If metadata appears damaged or missing from a valuable clone, preserve the entire folder and seek a recovery plan before any write operation.
If several project copies exist, compare their remote URLs and latest commits before selecting one. Similar folder names can hide different branches, stale archives, or unfinished local work that should not be merged casually.
- If pwd points at a workspace containing several projects, enter the specific clone before repeating rev-parse. A successful result naming the workspace itself may reveal an accidentally initialized parent repository; compare that root with the intended project instead of accepting any successful Git response.
- A linked worktree can use a .git file rather than a .git directory. Do not declare its metadata missing based only on a directory listing. Let git rev-parse --git-dir identify the metadata location, and preserve that file when investigating a copied or relocated worktree.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.