You created the repository, added the remote, ran the push, and Git answered with this: ```text error: src refspec main does not match any error: failed to push some refs to 'git@github.com:you/your-repo.git' ``` The message is about your machine, not the server. `git push origin main` asks Git to send a local branch named `main`, and Git is saying no such branch exists here. Four things cause that, and the first two account for most of it. All output below came from Git 2.55. ## Find the Cause in One Command ```bash git branch --show-current && git log --oneline -1 ``` Read the result: * **Nothing printed at all.** You have no commits yet. Go to Fix 1. * **A branch name that isn't the one you pushed** (`master` when you pushed `main`). Go to Fix 2. * **The right branch and a commit.** You mistyped the branch name in the push. Go to Fix 3. `git status` answers the same question in more words: "No commits yet" is the phrase to look for. ## Fix 1: Commit Something First A branch in Git points at a commit, so a branch with no commits doesn't exist yet, even though `git branch --show-current` prints a name. This is the usual case right after `git init`: files staged, nothing committed. ```bash git status --porcelain # 'A file.txt' means staged, not committed git add . git commit -m "First commit" git push origin main ``` Staging is not committing. `git add` alone leaves you with the same error, because there's still no commit for the branch to point at. ## Fix 2: Push the Branch You Actually Have Git init created `master` for years, and many machines still do. GitHub names the default branch `main`, so the branch you have and the branch you push differ. ```bash git branch --show-current # master git push origin main # error: src refspec main does not match any ``` Push the branch you have: ```bash git push origin master ``` Or rename it to match the remote, which is usually what you want: ```bash git branch -M main git push -u origin main ``` Set the default for new repositories so this stops happening: ```bash git config --global init.defaultBranch main ``` `-M` renames the branch and overwrites any existing one of that name. `-u` records the upstream, so later pushes are a bare `git push`. ## Fix 3: Check the Branch Name for Typos The refspec is echoed back to you verbatim, so the error names the branch Git looked for: ```text error: src refspec mian does not match any ``` That is `mian`, not `main`. Compare the name in the error with `git branch --show-current`, character by character. The same applies to a branch you deleted or never created locally. ## Fix 4: Push the Current Branch Without Naming It When you keep hitting the wrong name, let Git supply it: ```bash git push -u origin HEAD ``` `HEAD` means the branch you're on, so the name can't disagree with reality. After the first `-u` push, `git push` alone does the right thing. ## Why the Second Line Appears The error always arrives in a pair: ```text error: src refspec main does not match any error: failed to push some refs to 'git@github.com:you/your-repo.git' ``` The second line is a consequence, not a separate problem. Git had nothing to send, so the push failed. If the second line instead mentions permissions or authentication, you have a different problem: see [Fix Permission Denied (publickey)][ssh-publickey]. ## Verify ```bash git push -u origin main git branch -vv # the branch now tracks origin/main git ls-remote --heads origin ``` `git ls-remote` asks the server what branches it has. Seeing your branch there means the push landed. ## Related Content * [Fix Permission Denied (publickey) in SSH and GitHub][ssh-publickey] covers the authentication error that stops a push for a different reason. * [Fix GitHub Push Declined Email Privacy Error][push-declined] covers the third error people hit on a first push to GitHub. ## References * [git-push(1)][git-push-man], for refspec syntax and what `HEAD` means in a push. * [Git Book: Remote Branches][git-book-remotes], for how local branches map to remote ones. [ssh-publickey]: https://jeffbailey.us/blog/2019/11/10/setting-ssh-key-permissions/ [push-declined]: https://jeffbailey.us/blog/2020/01/20/push-declined-due-to-email-privacy-restrictions-on-github/ [git-push-man]: https://git-scm.com/docs/git-push [git-book-remotes]: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches