git push origin master
To https://gitee.com//hello-git.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com//hello-git.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.
这个错误是因为你本地的仓库与远程仓库中的内容不同步,需要先拉取远程仓库的最新代码合并到本地仓库再进行 push 操作。你可以运行以下命令来解决该问题:
git pull origin master --allow-unrelated-histories
该命令将从远程仓库拉取最新代码并合并到本地仓库中。如果出现冲突,需要手动解决冲突后再进行提交。
然后再运行 git push origin master 命令即可将本地代码推送到远程仓库。