Git errors
Status: đ© COMPLETE Last updated: 2026-06-21 Plain-English tagline: The Git messages that look scary but mean simple things. Paste the fragment, find the fix.
What this is
Gitâs error messages have a specific tone â terse, technical, frequently scary. Most of them mean simple things once you decode them. This is the decoder.
For rescue scenarios broader than a single error message, see Git rescue moves đ©.
âfatal: not a git repositoryâ
What it means: Youâre in a folder that isnât tracked by Git.
Fix:
- You meant to be elsewhere:
cdto the right folder. - You meant to start a repo here:
git init. - The repo exists but the
.gitfolder is missing: something got deleted; re-clone or restore from backup.
âfatal: refusing to merge unrelated historiesâ
What it means: You tried to merge two branches with no shared commits. Usually happens when you initialize a fresh repo locally, then git pull from a different existing repo.
Fix:
git pull origin main --allow-unrelated-historiesYouâll likely get conflicts on every file. Resolve them, commit. Future pulls work normally.
Better prevention: Always clone first, then add your code. Donât git init locally and then try to pull from an unrelated remote.
âYour branch is behind âorigin/mainâ by N commitsâ
What it means: Others (or another machine of yours) pushed commits since your last fetch. Yours doesnât have them yet.
Fix:
git pullIf that fails because you have uncommitted local changes:
git stash
git pull
git stash popâYour branch and âorigin/mainâ have divergedâ
What it means: You have local commits the remote doesnât, AND the remote has commits you donât. Both sides moved forward independently.
Fix: decide whether to merge or rebase.
git pull # default: merge (creates merge commit)
# OR
git pull --rebase # rebase your commits onto remote's tipFor solo work, rebase is cleaner. For shared branches, merge is safer.
âUpdates were rejected because the tip of your current branch is behindâ
What it means: Youâre trying to push, but the remote has commits you donât. Git refuses to overwrite them.
Fix: Pull first, then push.
git pull
# (resolve any conflicts)
git pushDonât reach for --force here â that overwrites the remoteâs commits. Use --force-with-lease only when you genuinely meant to rewrite history (e.g. after a rebase) and youâre the only one on the branch.
âAborting commit due to empty commit messageâ / âPlease tell me who you areâ
What they mean:
- Empty commit message: the editor closed without a message saved.
- âPlease tell me who you areâ: you havenât set
user.nameanduser.emailin Git config.
Fix:
git config --global user.name "George"
git config --global user.email "you@example.com"For the empty message, just retry with -m:
git commit -m "Your message here"âfatal: cannot do a partial commit during a mergeâ
What it means: Youâre in the middle of a merge with conflicts, and you tried to git commit <some-file> instead of staging everything.
Fix:
git add <all-conflicted-files> # not just some
git commit # without specifying filesâCONFLICT (content): Merge conflict in â
What it means: Git couldnât auto-merge the file. You need to resolve the conflict manually.
Fix:
- Open the file. Find the
<<<<<<<,=======,>>>>>>>markers. - Edit to be what you want. Delete the markers.
git add <file>.- After all conflicts:
git commit(for merge) orgit rebase --continue(for rebase).
Reference: Resolving merge conflicts đ© â full walkthrough.
âerror: pathspec âXâ did not match any file(s) known to gitâ
What it means: You referred to a file or branch by a name Git doesnât recognize.
Common causes:
- Typo in the file or branch name.
- File isnât tracked yet.
git checkout file.txtfails on untracked files â usegit restoreinstead, or you need togit addfirst. - Branch doesnât exist locally.
git switch feature/xfails iffeature/xis only on the remote. Trygit switch -c feature/x origin/feature/x.
âPermission denied (publickey)â
What it means: Youâre trying to push/pull via SSH but your SSH key isnât set up (or isnât authorized for this repo).
Fix:
- Generate an SSH key:
ssh-keygen -t ed25519 -C "you@example.com" - Upload the public key (
~/.ssh/id_ed25519.pub) to GitHub â Settings â SSH keys. - Test:
ssh -T git@github.comshould say âHi!â
Workaround: switch to HTTPS for that remote:
git remote set-url origin https://github.com/u/r.gitâfatal: detected dubious ownership in repositoryâ
What it means: The folder is owned by a different user than the one running Git. Common after copying a project between machines.
Fix:
git config --global --add safe.directory <path>
# Or for any folder:
git config --global --add safe.directory '*'The latter disables the safety check globally â fine for personal machines, less ideal on shared servers.
âAuto-merging X / CONFLICT (modify/delete)â
What it means: One branch deleted the file; the other modified it. Git canât decide which you want.
Fix:
# Keep the deletion:
git rm <file>
# Keep the modification (restore the file):
git add <file>
# Either way, after deciding:
git commitâcould not lock config file .git/config: File existsâ
What it means: Another Git process is running (or crashed and left a lock file).
Fix:
# Confirm no other Git process is actually running, then:
rm .git/index.lock # if it's the index lock
rm .git/config.lock # if it's the config lock(On Windows PowerShell: Remove-Item .git\index.lock.)
âYou are in âdetached HEADâ stateâ
What it means: You ran git checkout <hash> (or similar) and youâre not on any branch. Commits you make wonât belong to a branch and could be lost.
Fix:
# To stay on this commit but on a branch:
git switch -c rescue-branch
# To go back to where you were:
git switch main # or whatever you came fromIf you made commits while detached, git reflog will show them â donât panic.
Reference: Git rescue moves â âDetached HEAD"
"There is no tracking information for the current branchâ
What it means: You ran git pull or git push without arguments, but Git doesnât know which remote branch to use.
Fix:
# Set the upstream for this branch:
git push -u origin <branch-name>
# Or pull explicitly:
git pull origin <branch-name>âRefusing to delete the current branchâ
What it means: You tried git branch -d <branch> while youâre on that branch.
Fix: switch to a different branch first.
git switch main
git branch -d <branch>âfatal: The current branch X has no upstream branchâ
What it means: You tried to git push but this branch was never pushed before. Git doesnât know where to push to.
Fix:
git push -u origin <current-branch>The -u (or --set-upstream) tells Git âremember this for next time."
"warning: LF will be replaced by CRLF in â
What it means: Youâre on Windows with core.autocrlf set, and Git is converting line endings.
This is a warning, not an error â Git is doing what you asked. If itâs noisy:
# Confirm your config:
git config --global core.autocrlf
# Recommended values:
# Windows: true
# Mac/Linux: inputTo suppress the warning specifically:
git config --global core.safecrlf falseâerror: failed to push some refsâ (with no clearer message)
What it means: Generic push failure. Usually one of:
- Remote has commits you donât (most common). â
git pull. - Pre-receive hook on the remote rejected your push (branch protection rules). â Open a PR instead.
- Authentication failure. â Re-check
gh auth statusor your SSH setup.
âfatal: I donât handle protocol âhttpââ
What it means: You set a remote URL with a typo or bad protocol.
Fix:
git remote -v # see current URLs
git remote set-url origin https://github.com/u/r.gitSee also
- Common errors â index đ©
- Build errors đ©
- Git basics đ©
- Git rescue moves đ© â the broader âI broke Gitâ toolkit
- Resolving merge conflicts đ©
- Branches & merging đ©
- Rebase vs merge đ©
- Git cheat sheet đ©
- gh CLI cheat sheet đ©
- How-to: Rescue a broken Git branch đ©
Sources
- Pro Git book â common Git errors
- GitHub docs â common Git errors
- Oh Shit, Git!?! â the classic rescue reference