git push error failed to push some refs to solution

Problem specification
When we found a problem in the Github repository, you changed it online on Github; Or you can just add a README file or something to a library on Github without synchronizing it. Push fails when you have a commit again to commit from the local library to the remote Github library.

I edited a file online in github library, and it was not synchronized to the local library. After that, I added the file test.txt in the local library and tried to submit it to github, but the following error occurred: error: failed to push some refs to.

A statement in advance
For the code lost in the comments, it should be emphasized again that the base should be used with caution, and the branch should be determined before operation. In this case, the master branch is taken as an example, and the loss of the code caused by the wrong branch should be taken as the consequence.
The solution
The problem is that the remote library is inconsistent with the local library, so we can just synchronize the remote library to the local library. Note: I use the master branch here, please change the branch according to your own development branch.

git pull --rebase origin master

This directive merges updates from the remote library into the local library – the rebase function is to cancel the commit from the local library and connect them to the updated version library.

The following is a graphical explanation of the occurrence and resolution of the error situation

git pull –rebase origin master means to cancel commit records, temporarily save them as patches (in the “.git/rebase” directory), synchronize the remote repository to the local repository, and finally merge the patches into the local repository.

will then be able to push the local library into the remote library.

Read More: