You ran your first push in a new repository and Git stopped:
error: src refspec main does not match any
error: failed to push some refs to 'git@example.com:acme/web.git'
Nothing is broken on the server. src refspec is the source side of the push: the local branch you named. Git looked for a commit under that name and found none, so there is nothing to send.
Two causes account for almost every case: the name doesn’t match your branch, or the branch has no commit yet.
Check the local branch name
Ask Git which branch you are on, then list the branches that exist:
git branch --show-current
git branch --list
fix/cart-total
* fix/cart-total
A typo in the push command gives the same error, even when the branch has commits:
git push -u origin fix/cart-totl
error: src refspec fix/cart-totl does not match any
error: failed to push some refs to 'git@example.com:acme/web.git'
Compare the name in the error with the list. Another common mismatch: you typed main but the branch is master, or the other way round. Names are case-sensitive.
Check that the branch has a first commit
A new repository has a branch name but no commits, and Git can’t push a branch that points at nothing. git status -sb shows it:
git status -sb
## No commits yet on fix/cart-total
A a
A a is a file you staged but have not committed. Commit it:
git commit -m "Fix cart total"
git status -sb
## fix/cart-total
If git status shows no files at all, there is nothing to commit yet: add your files with git add, then commit.
Push the verified source
Check that the branch now resolves to a commit, then push it by its exact name:
git rev-parse --verify fix/cart-total
git push -u origin fix/cart-total
57777f4600886a33f477065a93d87f61fc534fb2
To git@example.com:acme/web.git
* [new branch] fix/cart-total -> fix/cart-total
branch 'fix/cart-total' set up to track 'origin/fix/cart-total'.
The first line is the commit the branch points at. If git rev-parse prints fatal: Needed a single revision, the name still doesn’t exist: go back to the list above.
Confirm the remote branch
List the branches on the remote and compare the hash with your local one:
git ls-remote --heads origin
57777f4600886a33f477065a93d87f61fc534fb2 refs/heads/fix/cart-total
Same hash, same name: the push worked.
Related errors
- A plain
git pushon a new branch fails with a different message, covered in Fix: The current branch has no upstream branch. git push origin HEADon a branch with no commits gives the samesrc refspec HEAD does not match any. The cause is the same: commit first.
See what is waiting to be pushed
push& (Pushand) is a Mac menu bar app that shows the commits waiting to be pushed in all your repositories. See the features.