Push to origin/Master was rejected [How to Solve]

Today, the leader created a new git warehouse for me, and a file readme. MD
already exists in the GIT warehouse. As usual, I operate locally as follows:

git init //Initialize the repository
git add . (file name) //add the file to the local repository
git commit -m "first commit" //add file description information
git remote add origin + remote repository address //link the remote repository and create a master branch
git push -u origin master //Push files from the local repository to the remote repository

But tip:

Reason: readme.md already exists in the new git warehouse, but the files of the local warehouse and the remote warehouse have not been associated. Therefore, we first associate the files of the two warehouses and then submit them
enter the commands in the terminl window of idea

git pull
git pull origin master
git pull origin master --allow-unrelated-histories

Then push the project again to succeed
if you still report an error, you can delete the local. Git folder and re associate the file:


git init //Initialize the repository
git add . (file name) //add the file to the local repository
git commit -m "first commit" //add file description information
git remote add origin + remote repository address //link remote repository, create master branch
#Associate files
git pull
git pull origin master
git pull origin master --allow-unrelated-histories
#push the code to the remote branch
git push -u origin master //Push files from the local repository to the remote repository

Read More: