Skip to content
Happy Programming Guide
Start learning
Coding Tools

How to Fix Git “fatal: remote error” and Push Failures

The Git push errors that stop beginners — rejected non-fast-forward, authentication failed, repository not found — each with what it means and the fix.

A red ladybird on a leaf in the sun

Git push failures are alarming and almost always one of five things. Read the first line of the message and match it below.

1. Updates were rejected#

Output
! [rejected]        main -> main (fetch first)
error: failed to push some refs to '...'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally.

This is Git stopping you from destroying someone’s commits — including your own, made through the GitHub web interface.

Bring the remote work down first, then push:

Terminal
git pull --rebase
git push

--rebase replays your commits on top of theirs, giving a straight history. A plain git pull works too and creates a merge commit.

If the pull produces a conflict, resolve it, then:

Terminal
git add .
git rebase --continue
git push

2. Authentication failed#

Output
remote: Support for password authentication was removed.
fatal: Authentication failed for 'https://github.com/...'

GitHub stopped accepting account passwords over HTTPS. Two options:

Personal access token. Generate one in GitHub’s developer settings and use it in place of your password when Git prompts. Your credential manager will remember it.

SSH, which avoids the prompt entirely:

Terminal
ssh-keygen -t ed25519 -C "you@example.com"
cat ~/.ssh/id_ed25519.pub          # add this to GitHub → SSH keys

git remote set-url origin git@github.com:you/repo.git
ssh -T git@github.com              # test it

If Git keeps offering an old cached password on Windows, clear it in Credential Manager under git:https://github.com.

3. Repository not found#

Output
remote: Repository not found.
fatal: repository 'https://github.com/you/repo.git/' not found

Confusingly, this is also what you get for a private repository you are not authenticated for — GitHub does not distinguish, on purpose.

Terminal
git remote -v                       # what URL is Git actually using?
git remote set-url origin https://github.com/you/correct-repo.git

Check the spelling, the owner name, and that you are signed in as an account with access.

4. src refspec main does not match any#

Output
error: src refspec main does not match any
error: failed to push some refs

You are pushing a branch that does not exist locally — nearly always because there are no commits yet, or the branch is called master.

Terminal
git status                # any commits?
git branch                # what is this branch called?

git add .
git commit -m "First commit"
git branch -M main
git push -u origin main

5. No upstream branch#

Output
fatal: The current branch add-search has no upstream branch.

The branch exists locally and the remote has never heard of it:

Terminal
git push -u origin add-search

The -u links them, so plain git push works from then on.

When you are lost#

These four commands tell you where you actually are:

Terminal
git status                 # branch, staged and unstaged changes
git remote -v              # where push and pull go
git log --oneline -5       # the last five commits
git branch -vv             # local branches and their remotes

And if you have made a mess locally but committed along the way, git reflog lists recent states you can return to — including commits no branch points at any more.

Questions people ask#

What does “fatal” mean in Git?

Only that Git stopped rather than continuing. It is not a comment on the severity — most fatal messages are routine and fixable in one command.

Should I use HTTPS or SSH?

SSH once you are pushing regularly — you set it up once and never see a prompt again. HTTPS with a token is fine and simpler to start with.

Can I undo a push?

git revert <commit> creates a new commit undoing the change, which is safe on shared branches. Rewriting history after pushing causes problems for everyone else.

Why does Git ask who I am?

Run the two config commands once: git config --global user.name "Your Name" and git config --global user.email "[email protected]".

Where to go next#

Next lessonGit and GitHub explained

Keep reading

Keep going — pick your next guide

The fastest way to improve is to read one guide, then build the thing it describes. Start with the basics, or jump straight to a project.

Ask a question or share what worked

Your email address will not be published. Required fields are marked *