error: src refspec master does not match any error: failed to push some refs to ‘github.com:github

created at 10-05-2021 views: 36

problem description

problem description

An error occurred when uploading code to Github using Git, prompt

error: src refspec master does not match any
error: failed to push some refs to'github.com:Username/Test.git

Start searching on the Internet for corresponding solutions. Most of the performance problems are in the README.md file. You need to merge the GitHub warehouse and the local warehouse to use

git pull --rebase origin master

But can't solve my problem
However, it is indeed possible to upload successfully without creating a README file when re-creating the warehouse and following the normal steps (this makes me very confused)
Finally found a solution today

Cause of the problem

1. The github project is named main by default

The github project is named main by default

2. Due to the different warehouse names, the remote and local warehouses cannot be associated

Solution

Unify the remote and local warehouse names

1 Solve git file, github comes with README file

1.1. Change the name of the local master warehouse to the remote main

Rename command: git branch -m oldBranchName newBranchName
(for example: git branch -m master main)

1.2. git push -u origin main

2. Don't solve the git problem, upload README.md

2.1. Create a README.md file in the local warehouse

2.2. Follow the normal upload steps

Upload steps
1.git clone git@github.com: username/warehouse-name.git

2. Copy the files that need to be uploaded to the newly appeared folder

3.git add . (note the .)

4. git commit -m "comment"

5. git push -u origin master (the code becomes git push -u origin main after changing to main)

created at:10-05-2021
edited at: 10-05-2021: