Fix "fatal: not a git repository" by locating the repository in PowerShell
Cause: fatal: not a git repository means Git could not find a repository from the current location.
Fix: Check the current folder, move to the existing project, and verify the root Git recognizes. Seeing source files does not establish that the folder is a repository.
These commands use Windows PowerShell. Replace the practice name my-project with the project you saved or cloned. When locating an existing repository, do not run git init at the error location.
These screenshots show the actual commands and results. Select an image to open it at full size. On small screens, scroll sideways inside a wide image.
1. Check where you ran the command
When git status reports fatal: not a git repository, run these commands in the same PowerShell session.
Get-Location
Get-ChildItem -DirectoryGet-Location shows where commands are running. The second command lists folders immediately below that location. If it includes my-project, continue to the next step. This is not a search of the whole PC, so an absent folder does not prove the repository is gone.
If the folder is not listed, find the location where you originally cloned or saved the project in File Explorer and read its address bar. Compare the folder open in VS Code with the terminal's current location. The original screenshot shows the command running outside the repository.
Expected resultThe current location produces the not a git repository error.
2. Move to your existing project folder
After confirming that my-project exists below the current location, run:
Set-Location -LiteralPath '.\my-project'
Get-Location
git rev-parse --show-toplevel
git rev-parse --is-inside-work-tree
git statusIf it is elsewhere, replace the quoted path on the first line with the full path you confirmed in File Explorer. -LiteralPath treats the path literally. Keep the complete path in quotes when it contains spaces. If changing location fails, stop and correct the path before running the remaining commands.
--show-toplevel prints the root of the working tree Git recognizes. --is-inside-work-tree prints true when you are inside it. Check that the root is the project you intended. The original screenshot's cd my-project is another way to enter the same folder; the commands above also verify the resulting location.
Expected resultIn my-project, git status shows main and the status of README.
3. Check that repository status replaces the error
Once the repository is found, git status shows its branch and file status. The original example's No commits yet means the repository exists but has no first commit. Resolving the location error does not require a commit or push.
| Result | Meaning and next action |
|---|---|
The root is the intended project and the check prints true | Continue working in that repository. |
A subfolder such as src reports the parent project's root | This is normal. You do not have to return to the root for every Git command. |
| The root is a different project | You may be inside another repository. Recheck the path before editing files. |
fatal: not a git repository persists | Use the next step to distinguish a source ZIP from a clone. |
Separate synthetic folders verified the outside-folder failure, success after entering the project, and the same root reported from its src subfolder. These checks only locate the repository; they do not connect to a remote or create a commit.
Find the original repository when the folder came from a ZIP
You can list names including hidden items inside the problem folder:
Get-ChildItem -Force -Name.git can be a directory or a file containing repository connection information. A subfolder can also belong to a parent repository without having its own .git entry. Use the root checks above rather than deciding from one name alone.
GitHub's Download ZIP provides a snapshot of files, not a clone containing the entire history. In a separate synthetic ZIP, the README content was identical but repository metadata was absent; both git status and the root check failed.
Preserve any files you edited in the ZIP. Look for the original clone. If none exists, verify the project's official repository address, clone into a different new folder, and compare your changed files before transferring them. If .git was deleted from an existing working copy, check its original clone or backup first. Initializing a new repository does not restore the old commit history.
Expected result: Distinguish a source ZIP from a repository and choose an existing or new clone while preserving edited files.
Expected resultgit status completes successfully and shows the main branch status.
References
Another Git problem?
Compare staged changes and working files with Git diff →
Fetch a remote branch to fix Git's invalid reference error →


