解决Git上传代码error: failed to push some refs to ‘xxx‘hint:(e.g., ‘git pull ...‘) before pushing again错误

在使用git提交代码时会出现error: failed to push some refs to 'xxxx的错误,如下图:

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上传代码error: failed to push some refs to ‘xxx‘hint:(e.g., ‘git pull ...‘) before pushing again错误

原来使用的提交命令是git push -u origin 分支名

不妨尝试一下使用覆盖提交的方式

git push -f origin 分支名

其中“-f”是覆盖提交的参数。

解决Git上传代码error: failed to push some refs to ‘xxx‘hint:(e.g., ‘git pull ...‘) before pushing again错误

通过以上可以证明提交代码的权限是存在的,但是为什么不能更新代码呢?

请看第二、三行报错:

解决Git上传代码error: failed to push some refs to ‘xxx‘hint:(e.g., ‘git pull ...‘) before pushing again错误

大致意思是要先拉一下代码,再推一次代码,拉代码使用git push

先命令:git pull

后命令:git push

解决Git上传代码error: failed to push some refs to ‘xxx‘hint:(e.g., ‘git pull ...‘) before pushing again错误

问题解决!

 

使用git bash的完整提交代码命令如下:

#如果之前有初始化 init 需要删除

命令: rm -rf .git

#初始化本地仓库

命令: git init

#连接远程git仓库

命令: git remote add origin 仓库地址(注意是带有.git结尾的地址)

#创建并切到分支
命令: git checkout -b 分支名

#添加本地需要提交的代码(.表示所有)
命令: git add .

#提交代码并添加说明
命令: git commit -m "说明内容"

#上传代码代码到分支(首次要先用git pull下拉代码)
命令: git push origin 分支名

#强覆盖式上传
命令: git push -f origin 分支名