Common Git Errors: Setup and Access
Setup and access errors are the messages Git prints when it can't find a repository, doesn't know who you are, can't prove to a server who you are, or finds the repository busy or owned by someone else. They are most common on a new computer, in a new project or on a CI server. This page shows each one exactly as Git prints it, with what it means, the fix, and how to avoid it. The examples on this page start from a computer where Git has not been set up yet.
Arriving at a new office is similar. Your badge doesn't open the doors yet, nobody knows your name, and someone else is using the meeting room. Each problem has a simple fix, once you know which one it is.
Not a Git Repository
mkdir notes
cd notes
git statusfatal: not a git repository (or any of the parent directories): .gitWhat it means: Git looked for a .git folder in the current folder and every folder above it, and found none. You are either in the wrong folder, or the project was never made a repository.
The fix: cd into the project (pwd shows where you are), or run git init if this folder should be a new repository. A common cause is opening a terminal in the parent folder of a freshly cloned project: git clone creates a new folder, so cd into it.
Author Identity Unknown
On a new computer, the first commit fails. On some systems, Git doesn't fail but guesses a name and address from your computer's user account and host name, and commits with them; the setting user.useConfigOnly turns that guessing off, so you always get the clear error instead. It is a good setting to have:
cd ..
git config --global user.useConfigOnly true
git init --quiet --initial-branch=main fee-tracker
cd fee-tracker
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit -m "Add the term fee"Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: no email was given and auto-detection is disabledWhat it means: every commit records an author name and email address, and Git doesn't know yours. Without user.useConfigOnly, some systems make the commit anyway with a guessed identity such as navika@laptop.local and print a long warning; fix that commit with git commit --amend --reset-author after setting your identity.
The fix: set them once, as the message says, then commit again:
git config --global user.name "Navika Anamaneni"
git config --global user.email "navika@example.com"
git config --global init.defaultBranch main
git commit --quiet -m "Add the term fee"
git log --format="%an <%ae>: %s"Navika Anamaneni <navika@example.com>: Add the term feeAvoid it: set your name, email address and default branch name as the first step on every new computer (see "Git Config"). Use the same email address as your hosting account, so commits are linked to you.
SSH Permission Denied
When you use an SSH URL (git@github.com:...) and the server doesn't accept any of your keys, Git prints this. It needs a real server and account, so it is shown without running here:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.What it means: the first line comes from SSH: you reached the server, but none of the keys your computer offered is registered on your account (or you have no key at all). The rest is Git's message, which also appears when the repository doesn't exist or you have no access to it.
The fix:
- Test the connection:
ssh -T git@github.com(orgit@gitlab.com,git@bitbucket.org). A working key prints a greeting with your user name. - If you have no key, create one and add the public half to your account (see "Adding an SSH Key").
- If you have a key but it isn't used, add it to the agent (
ssh-add ~/.ssh/id_ed25519) or name it in~/.ssh/config. - Check the URL with
git remote -v, and that your account has access to that repository.
Authentication Failed (HTTPS)
With an HTTPS URL, wrong or missing credentials end like this:
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/navika-anamaneni/fee-tracker.git/'What it means: hosting platforms no longer accept your account password for Git over HTTPS. They need a personal access token (or app password), or a sign-in through a credential helper. The remote: line is the server's wording, which differs between platforms.
The fix: use the Git Credential Manager, which opens a browser to sign in and stores the result (it comes with Git for Windows, and can be installed on macOS and Linux), or create a token on the platform and paste it when asked for a password. If an old, wrong password is stored, remove it from your system's credential store (Windows Credential Manager, macOS Keychain) and try again. Switching the remote to SSH (git remote set-url origin git@github.com:...) is the other way out. See "Useful Git Settings" for credential helpers.
LF Will Be Replaced by CRLF
Advitha, on Windows, has core.autocrlf set to true (the Git for Windows default). Adding a file that has Unix line endings prints a warning:
git config core.autocrlf true
printf "%s\n" 'Late fee: $250' > late.txt
git add late.txtwarning: in the working copy of 'late.txt', LF will be replaced by CRLF the next time Git touches itWhat it means: this is a warning, not an error. The file was added. Git is saying that the next time it writes late.txt into the working folder (on checkout), it will use Windows line endings (CRLF), while the repository keeps LF.
The fix: nothing is broken. To make line endings the same for everyone and silence surprises, add a .gitattributes file with * text=auto and specific rules such as *.sh text eol=lf (see "Git .gitattributes and Line Endings"). Then git add --renormalize . and commit.
git config --unset core.autocrlf
git commit --quiet -m "Add the late fee" Another Git Process Seems to Be Running
touch .git/index.lock
echo 'Exam fee: $800' > exam.txt
git add exam.txtfatal: Unable to create '/home/navika/projects/fee-tracker/.git/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.What it means: Git creates .git/index.lock while it changes the index, so that two commands never change it at the same time, and deletes it when finished. If a Git command crashed, was killed, or an IDE is running Git in the background right now, the file is still there.
The fix: first wait a moment and close any IDE or GUI client that might be running Git, then try again. If no Git process is running (check your task manager or ps aux | grep git), delete the leftover lock file:
rm .git/index.lock
git add exam.txt
git status --shortA exam.txtDetected Dubious Ownership
fatal: detected dubious ownership in repository at '/srv/fee-tracker'
To add an exception for this directory, call:
git config --global --add safe.directory /srv/fee-trackerWhat it means: the repository belongs to another user account, which happens in Docker containers, CI jobs, shared folders and on external drives. Git refuses, because that user's settings and hooks could run programs as you.
The fix: if you trust the repository, run the command Git prints. Avoid safe.directory '*'. See "Keeping Secrets Out of Git" for the full explanation.
Build Output Was Committed
Not an error message, but one of the most common problems: a build folder was committed before .gitignore listed it:
git commit --quiet -m "Add the exam fee"
mkdir -p target/classes
echo "binary" > target/classes/Fees.class
git add .
git commit --quiet -m "Add the fee classes"
git ls-filesexam.txt
fees.txt
late.txt
target/classes/Fees.classThe fix: remove the folder from Git, but not from your disk, and ignore it from now on:
git rm -r --cached --quiet target
echo "target/" >> .gitignore
git add .gitignore
git commit --quiet -m "Stop tracking build output"
git ls-files
ls target.gitignore
exam.txt
fees.txt
late.txt
classesExplanation: --cached removed the files from the index only, so the build output is still on disk (and ls target shows it), while the next commit no longer contains it. Old commits still do. That is harmless for build output, but if the folder was huge or contained secrets, rewrite the history as in "Removing Files from History".
Common Mistakes
Running git init in your home folder by accident. Every file you own then appears in git status. Delete the .git folder that you created there (rm -rf ~/.git, carefully), not your files.
Typing your account password for HTTPS pushes. Use a token or the Git Credential Manager.
Deleting index.lock while an IDE is running Git. Close it first.
Turning off line-ending conversion to make the warning go away. Use .gitattributes to make the rules explicit instead.
Under the Hood
Git finds the repository by walking up from the current folder, looking for .git (a folder, or a file pointing to one), and stops at the file system root or at a folder listed in GIT_CEILING_DIRECTORIES. Identity comes from user.name and user.email, which can be overridden for one command with GIT_AUTHOR_NAME and friends. For HTTPS, Git asks the configured credential helper for a user name and password or token; for SSH, it runs ssh, which offers the keys from your agent and ~/.ssh, and the server checks them against your account. Lock files are created with an exclusive "create only if it doesn't exist" call, which is why a leftover lock blocks every later command until it is removed.
Interview Corner
What does "fatal: not a git repository" mean?
Git found no .git folder in the current folder or any folder above it. cd into the project, or run git init to make a new repository.
How do you fix "Permission denied (publickey)"?
Check the connection with ssh -T git@github.com, create an SSH key if needed, add the public key to your account, make sure the agent uses it, and check the remote URL and your access rights.
Why does a push over HTTPS fail with "Authentication failed" although the password is right?
Hosting platforms don't accept account passwords for Git. Use a personal access token or the Git Credential Manager, or switch to SSH.
What is index.lock, and when may you delete it?
A lock file Git creates while changing the index. Delete it only when no Git process is running, for example after a crash.
Practice
Challenge: a lost identity. Unset user.email globally, try to commit a change, and then fix it with a repository-only email address.
What does Git print? Before you open the solution, decide whether Git still knows the name.
Show solution
git config --global --unset user.email
echo 'Bus fee: $1,500' > bus.txt
git add bus.txt
git commit --quiet -m "Add the bus fee" 2>&1 | grep -E "fatal|Author identity"
git config user.email "navika@school.example.com"
git commit --quiet -m "Add the bus fee"
git log -1 --format="%an <%ae>"Author identity unknown
fatal: no email was given and auto-detection is disabled
Navika Anamaneni <navika@school.example.com>Git refused again: it still knows the name, but a commit needs the email address too, and user.useConfigOnly stops it from guessing one. With the email address set for this repository only (no --global), the commit works. A repository setting overrides the global one, which is how people use a work email address in work projects.
Checkpoint. On a computer or account where Git isn't set up, reproduce three errors from this page and fix them, then run git config --list --show-origin to see where each setting came from.
Key Takeaways
Quick reference
| Error | Fix |
|---|---|
fatal: not a git repository | cd into the project, or git init |
Author identity unknown | git config --global user.name and user.email |
Permission denied (publickey) | ssh -T git@<host>, add the key |
Authentication failed for 'https://...' | Token or Git Credential Manager |
LF will be replaced by CRLF | .gitattributes with * text=auto |
Unable to create '.../index.lock': File exists | Delete the lock if no Git is running |
detected dubious ownership | git config --global --add safe.directory <path> |
Was this tutorial helpful?