Push to origin/master was rejected (Git commit error)

When Android studio uses Git Push code to Coding, an error message of Push to origin/master was rejected will appear.

write picture description here

write picture description here

  I tried several times and found that this problem is very easy to occur when submitting to the code repository for the first time, because the initialized repository is not related to the local repository. Therefore, when submitting the new code for the first time, This error usually occurs.

solution:

Open the project directory and open Git Bash in the directory location corresponding to the git project.

write picture description here

input the command:

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

Then you can continue to push the code in android studio.

I hope it is useful to you who are not familiar with git, come on.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325583784&siteId=291194637