I created a new repo on
git remote add origin https://email@example.com/my_account/my_project.git
git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'https://firstname.lastname@example.org/my_account/my_project.git'
You have no
Consider the steps you did:
git init: this created a new, empty repository, with no commits.
Given that there are no commits, which branch or branches is / are the commits on? (This is a somewhat philosophical question, but it deserves your best attempt at an answer.)
git remote add origin url: this added a remote, which is basically just a short name for a URL. Your otherwise empty repository now has one remote, named
origin, which is short for the URL.
git push origin master: this asks your Git to push, to the other Git at the URL specified by the short name
origin, all the commits that are on your
master branch, that are not on their
master branch, and then set their
master branch to point to the same specific branch tip commit as your
Now, count all the commits in your repository. How many are there? How many commits should you expect your Git to push in step 3? How many commits are on branch
master? Can branch
master even exist if there are no commits on it? (This gets us back to the philosophical question in step 1.)
Now suppose you
git add some files to your index (the index is where you build the next commit), and then run
git commit. How many commits will you have? Which branch or branches will the commits be on? (This question is surprisingly tricky in the end, although in fact the obvious answer—"all of the new commits, which is therefore one single commit, will be on branch
master"—is the correct answer.)
In Git's world, a branch can never be empty—it can never have no commits. A branch that has no commits simply does not exist. Weirdly, however, you can be on such a branch. (These branches have two different adjectives used to describe or create them, depending on which Git command or output you're looking at: unborn branch and orphan branch.)
What it means to be on a branch in Git is that your next commit, the one you build up in the index, will extend that branch, adding a new commit to it. So the solution to your problem is to make at least one commit while you are on branch
master, so that branch
master comes into existence with that first commit you make. Then you will be able to push it.