gitgithub

git: error: src refspec main does not match any


I was trying to use git via VSCode, and because I didn't know how to use Git on VSCode, it messed up everything.
Then I tried to use CMD (Windows) as usual. I am learning, and I've never seen this kind of error before, so I don't know how to solve this.

But it's showing these errors when I try to push to the main branch:

error: src refspec main does not match any
error: failed to push some refs to 'myPathToRepo'

I tried:

I've seen other posts on StackOverflow and mostly they say "first commit and then push because this error arises when you're pushing without committing".

After deleting the .git/ folder and restarting, it starts to show this same error

>git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

>git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'myPathToRepo'

This is my first commit:

[master (root-commit) 061a06e] first commit

PS. I only have 'main' branch.

Commands that I ran:

git init
git remote add origin 'pathToMyRepo'
git add -A
git commit -m "first commit"
git push
git push -u origin main

Please help.


Solution

  • You don't have a branch called main. You have a branch called master.

    Either push with the correct name:

    git push -u origin master
    

    Or change your local branch name to main and use that:

    git branch -m main
    git push -u origin main