Solve error: failed to push some refs to'xxxx'

created at 11-10-2021 views: 2

Today, a part of the project was modified, and the following error was reported when using git push origin master to push to the remote warehouse:

error: failed to push some refs to 'https://github.com/ZJyoung1997/JZShop.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

The reason is that the files in the remote warehouse are different from our local warehouse. For example, your remote warehouse has a file Readme. md, but the local warehouse does not. This may happen. Mine is caused by the Readme. md file in the remote warehouse, but there is no such file in the local warehouse. It is also because I usually use the association computer for development in the association, and then use my own computer for development after returning to the dormitory. This may also be the cause of this problem. There is a solution to this situation, which is to kill the local warehouse directly, and then clone one from the remote, but this is obviously too troublesome, you can use the method of merging branches

solution

git pull --rebase origin master

The git pull command is used to obtain and integrate (integrate) from another repository or local branch, retrieve the update of a branch of the remote host, and merge it with the specified local branch.

fatal: 'master' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Use git pull origin master --allow-unrelated-histories to solve

created at:11-10-2021
edited at: 11-10-2021: