最近项目开发用到git,导师使用的是码云。
在Windows环境中使用Git连接码云,尝试push文件时报错:

*! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘git@gitee.com:huankai7/practice.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.

如图:
Git:解决Git向码云中push文件报错:! [rejected]        master -> master (fetch first)_项目开发
找了很多方法都是针对github的,最后找到一句命令行

$ git pull gitee master --allow-unrelated-histories
Git:解决Git向码云中push文件报错:! [rejected]        master -> master (fetch first)_git_02
执行后成功上传。
Git:解决Git向码云中push文件报错:! [rejected]        master -> master (fetch first)_git_03