Git Reference ยท Concepts
Common Git error messages
Decode the Git errors you meet most often: not a git repository, rejected push, divergent branches, merge conflicts, dirty tree, detached HEAD and more.
Git error messages are terse, but they are usually precise: they name the rule you tripped over and often print the command that fixes it. The trick is to read the first line (the cause) and the hint lines (the remedy) instead of the whole wall of text. Most errors fall into a few families: you are in the wrong place, Git refuses to overwrite work it cannot recover, or two histories disagree.
This page reproduces the errors you will meet most often in throwaway repositories, explains what each one is protecting you from, and lists the safe fix. Message wording varies slightly between Git versions, so match on the meaning rather than the exact text.
git status # first stop: where am I, what is changed? git log --oneline --graph --all -10 git reflog # where HEAD has been, if something looks lost
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Reading an error
Every message follows a rough shape: fatal: (the command stopped), error: (something failed, the command may continue), warning: or hint: (advice). The hint: lines are written by the Git developers for exactly the situation you are in, so read them before searching the web. You can silence a hint for good with git config --global advice.<name> false once you know it by heart.
Exit codes follow the same split: 128 is a fatal error such as a missing repository or bad revision, 1 is a command-specific failure such as a conflict or "nothing to commit", and 0 is success. Scripts should check these rather than parse text.
The errors, grouped by cause
You are in the wrong place
fatal: not a git repository (or any of the parent directories): .git(newer builds may say "or any parent up to mount point /"): there is no.githere or in any parent. Change into your project, or rungit init/git clone. If the folder used to work, check that.gitwas not deleted.fatal: detected dubious ownership in repository at '...': the folder belongs to another user, and Git refuses to read its config for safety. If you trust it, rungit config --global --add safe.directory <path>. See safe.directory.fatal: Not a valid object name mainorambiguous argument 'HEAD': unknown revision: the repository has no commits yet, or the name does not exist. Make a first commit, or check names withgit branch -a.
Nothing to do, or the wrong thing named
nothing to commit, working tree clean/no changes added to commit: you have not staged anything (see the staging area). Usegit add, orgit commit -afor tracked files.pathspec 'x' did not match any files: the path does not exist, is ignored, or the case is wrong.git add -foverrides ignore rules; see .gitignore.error: pathspec 'x' did not match any file(s) known to git:git checkout xorgit switch xfound no such branch or file. Fetch first if the branch lives on a remote.
Git refuses to lose your work
error: Your local changes to the following files would be overwritten by checkout: switching branches would clobber uncommitted edits. Commit them, orgit stash, then switch.error: Your local changes ... would be overwritten by merge: same protection formergeandpull.error: The following untracked working tree files would be overwritten: an untracked file has the same name as one in the branch you are moving to. Move or delete it.fatal: refusing to merge unrelated histories: the two branches share no common ancestor, typical when joining two separately created repositories. If that is intended, add--allow-unrelated-histories.
Two histories disagree
! [rejected] main -> main (fetch first)or(non-fast-forward): the remote has commits you lack, so a push would erase them. Integrate first withgit pull --rebase(orgit pullwith a merge), then push. Avoid--force; if you must overwrite, use--force-with-lease, which fails if the remote moved again.fatal: Need to specify how to reconcile divergent branches: both sides have new commits and nopull.rebaseorpull.ffsetting tells Git what to do. Pass--rebase,--no-rebaseor--ff-onlyonce, or setgit config --global pull.rebase true. See pull settings.CONFLICT (content): Merge conflict in f.txt/Automatic merge failed; fix conflicts and then commit the result: both sides changed the same lines. Edit the file to remove the<<<<<<<,=======,>>>>>>>markers,git addit, thengit commit(merge) orgit rebase --continue. To give up, rungit merge --abortorgit rebase --abort.fatal: You have not concluded your merge (MERGE_HEAD exists): a previous merge is still open. Finish or abort it.
Remotes and authentication
fatal: 'origin' does not appear to be a git repository: no remote of that name, or the URL is wrong. Checkgit remote -v.remote: Permission denied/Authentication failed: wrong credentials or no write access. Fix the credential helper or SSH key rather than retrying.fatal: unable to access '...': Could not resolve host: a network or proxy problem, not a Git problem.error: failed to push some refs: only the closing line of a longer message. Read the lines above it for the real cause.
HEAD and branches
You are in 'detached HEAD' state: HEAD points at a commit, not a branch, so new commits belong to no branch and become hard to find. Rungit switch -c new-branchto keep them, orgit switch -to leave. Details in detached HEAD.error: Cannot delete branch 'x' checked out at '...': you are on that branch, or another worktree is. Switch away first.error: The branch 'x' is not fully merged:git branch -dprotects unmerged work. Use-Donly after confirming withgit log main..x.
A file that will not go away or stay ignored
warning: LF will be replaced by CRLF: line-ending conversion notice from core.autocrlf; harmless but noisy.error: unable to create file ...: Filename too long(Windows): setgit config --global core.longpaths true.fatal: unable to auto-detect email address: setuser.nameanduser.email; see user settings.fatal: bad object/error: object file ... is empty: repository corruption, often from a crash or disk problem. Try git fsck, then re-clone and carry over unpushed work from the damaged copy.
Usage notes
- Fix the cause, not the symptom: forcing a push or deleting a lock file is the last resort, not the first.
fatal: Unable to create '.git/index.lock': File existsmeans another Git process is running or one crashed. Check that none is running, then delete the lock file.- If a command goes wrong halfway,
git statustells you which operation is in progress (merge, rebase, cherry-pick, bisect) and how to continue or abort it. - Almost nothing you committed is truly gone; see git reflog before you assume the worst.
- Search the exact first line of the message, without your paths and names, if you need outside help.