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.
The solution to this error is to either create a local and remote master branch that you can push the commit to or to push the commit to an existing branch – maybe main . These commands will create a master branch locally. And by pushing to origin master , the master branch will also be created remotely.
Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.
The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.
Git Push Origin pushes all the branches to the main branch. Git Push Origin Master pushes your master branch to the origin. Command for this: git push origin.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With