错误
To github.com:genghenggao/niuniu.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'github.com:genghenggao/niuniu.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.
分析
之所以出现这个原因,是因为我在线上生成、编辑了README.md文件,而本地代码文件中不包含它,所以线上线下就对不上了。
解决
将线上、线下代码进行合并
git pull --rebase origin main # 或者 git pull origin main --allow-unrelated-histories
然后再进行push
git push # 不行的话加上-f,-f表示将目前自己本机的代码库推送到远端,并覆盖 git push origin main -f
成功: