fatal: not a
git repository.
Git looked in this folder and every folder above it, and found no repository. Nothing is broken. You are in the wrong place, or the repository was never created here.
The exact message
what you seeyou@laptop my-project % git status
fatal: not a git repository (or any of the parent directories): .git
A repository is a folder that has a hidden .git folder inside it. Git walks up from where you are, one folder at a time, looking for that .git folder. The message means it reached the top of the disk and found none. The same message appears for git add, git commit, git log and most other commands.
What Git is looking for
a pictureA repository
my-project/ .git/ <- Git looks for this index.html notes.txt
Not a repository
my-project/ index.html notes.txt (no .git anywhere above)
Wrong folder
Downloads/ <- you are here
my-project/
.git/Step 1: find out where you are
10 secondsWhere am I?
Run pwd (macOS, Linux, Git Bash) or cd on its own (Windows cmd). It prints the folder you are in.
What is in here?
Run ls -a (dir /a on Windows cmd). The -a shows hidden items. Look for a line that says .git.
Is it above me?
No .git here? Run cd .. to go up one folder and look again. Git does this walk for you, so if it still fails, none of the parents have one either.
Step 2: match your case
one of threels -a shows no .git, and you never ran git init or git clonegit init turns the current folder into one. Then git status works.pwd shows a folder like Downloads, Desktop or your home folder, not your projectcd into the project folder, then try again. Tip: in Chapter 3 you saw how to open a terminal inside a folder.ls -a shows no .git.git folder was deleted or moved. It holds all your history.git init here only starts an empty history. Your old commits do not come back.Check it worked: after git init, git status prints On branch ... and No commits yet. The default branch name depends on your Git settings (Chapter 5 sets it to main).
See it happen
a real runyou@laptop my-project % mkdir demo && cd demo you@laptop my-project % git status fatal: not a git repository (or any of the parent directories): .git you@laptop my-project % git init Initialized empty Git repository in /home/you/demo/.git/ you@laptop my-project % git status On branch main No commits yet nothing to commit (create/copy files and use "git add" to track)
The branch name and the path in your own output will differ. The point: the same command that failed works right after git init.
Look-alike mistakes
same message, different causefatal: not a git repository (or any of the parent directories): .gitYou are inside the .git folder or a siblingRun cd .. until you are in the project folder that contains .git, not inside it.warning: Not a git repository. Use --no-index to compare two paths outside a working treeYou ran git diff outside a repositorygit diff is the one command that words it as a warning. The cause and the fix are the same as above.fatal: ambiguous argument 'HEAD~5': unknown revision or path not in the working tree.Different problem: you went further back than your historyThis one means you are in a repository. Run git log --oneline and count your commits first.Questions people ask
What does "not a git repository" mean?
Git could not find a .git folder in the current folder or in any folder above it. Without that folder Git has no history to work with.
Do I lose my files if I see this error?
No. The error only says Git has no repository to look at. Your files are untouched.
Should I run git init every time I see it?
Only if the folder was never a repository. If you are in the wrong folder, cd to the right one. If a .git folder was deleted, git init starts a new empty history and does not restore the old one.
Why does ls not show the .git folder?
It is a hidden folder. Use ls -a on macOS, Linux or Git Bash, or dir /a on Windows cmd.