error: src refspec main does not match any error: failed to push some refs to <url>

Viewed 17915
  1. To get practice with Github, I created a new directory on my computer that I wanted to push to Github.
  2. I added a .csv file and nothing else.
  3. I created a new repo on Github without initializing a README.
  4. I cd'd into the directory then used the following commands in Terminal:

git init

git add file1.csv

git commit -m "First commit"

git remote add origin <Github url from Quick Setup page>

git push -u origin main

And I got the following errors:

error: src refspec main does not match any

error: failed to push some refs to <url>

I searched for a solution and I came across this: git error: failed to push some refs to remote The answer selected says:

If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:

git pull --rebase origin master

git push origin master

What I don't understand is, why did this happen with a new directory on my computer and a new repo? No commits were made to the repo on Github so why should I have to git pull? I even tried doing this with a new empty directory and new empty repo (again) and I got the same result.

1 Answers

This is an unpleasant result of the master vs main controversy.

Your local GIT client created a default branch called master (when you initialized the repo with git init), but the remote repository on GitHub has no master - instead the default branch is called main.


Solution A - if you want to name the branch master

Run git push -u origin master instead of git push -u origin main

Or Solution B - if you want to name the branch main

Run git checkout -B main before git push -u origin main

Related