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#
! [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:
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:
git add .
git rebase --continue
git push2. Authentication failed#
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:
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 itIf Git keeps offering an old cached password on Windows, clear it in Credential Manager under git:https://github.com.
3. Repository not found#
remote: Repository not found.
fatal: repository 'https://github.com/you/repo.git/' not foundConfusingly, this is also what you get for a private repository you are not authenticated for — GitHub does not distinguish, on purpose.
git remote -v # what URL is Git actually using?
git remote set-url origin https://github.com/you/correct-repo.gitCheck the spelling, the owner name, and that you are signed in as an account with access.
4. src refspec main does not match any#
error: src refspec main does not match any
error: failed to push some refsYou are pushing a branch that does not exist locally — nearly always because there are no commits yet, or the branch is called master.
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 main5. No upstream branch#
fatal: The current branch add-search has no upstream branch.The branch exists locally and the remote has never heard of it:
git push -u origin add-searchThe -u links them, so plain git push works from then on.
When you are lost#
These four commands tell you where you actually are:
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 remotesAnd 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]".