# Fix “not a git repository” by finding the right folder

Canonical: https://githtml.com/guides/git-not-a-repository-error
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

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.

1. If the project is an archive, keep any edits safe and clone the original into a separate destination when you actually need its history.
2. If you find an existing clone elsewhere, compare revisions and local modifications before transferring files; do not overwrite one directory with the other.

````shell
pwd
git rev-parse --show-toplevel
git rev-parse --git-dir
git status
````

## Restore 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.

1. 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.
2. 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

- [Git reference: git](https://git-scm.com/docs/git)
- [Git reference: git-init](https://git-scm.com/docs/git-init)
- [Git reference: git-clone](https://git-scm.com/docs/git-clone)

## Related guides

- [Why Git says “nothing to commit” after you edited files](https://githtml.com/guides/git-nothing-to-commit-after-editing)
- [Fix a Git pathspec error by checking names and context](https://githtml.com/guides/git-pathspec-did-not-match-error)
- [Resolve Git’s divergent-branches pull warning](https://githtml.com/guides/git-pull-divergent-branches-reconcile)
- [Handle a non-fast-forward Git push rejection safely](https://githtml.com/guides/git-push-rejected-non-fast-forward)

Editorial approach: https://githtml.com/guides/about
