Failed to push some refs when using push

I create a repository in Github and on my local machine I ran the code:

git init
git branch -m main
git remote add origin https://github.com/.../Project.git
git push -u origin main

Instead of using master branch I want to use main branch.

When running git push -u origin main I get the error:

failed to push some refs to 'https://github.com/.../Project.git'

What am I doing wrong?

>Solution :

Is your local repo empty?

In this case, you need to add a file and commit it.

1. Run notepad test.txt (Windows) or touch test.txt (Mac)
2. Save the file.
3. git add . 
4. git commit -m "Initial commit"
5. git push -u origin main

Leave a Reply