error: failed to push some refs to

将本地新建项目推送到gitlab远程仓库时提示:error: failed to push some refs to ....。

异常信息:

D:\work\web>git push -u origin master
To https://xieyonghui.com/nick/web.git
 ! [rejected]    master -> master (non-fast-forward)
error: failed to push some refs to 'https://xieyonghui.com/nick/web.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决方法:

git pull --rebase origin master

说明:若执行完以上命令仍不能正常推送,可尝试以下方法。

如果条件允许删除远程仓库重建,可在gitlab中找到项目所在仓库,通过Setting-->General-->展开Advanced setting滑到页面最后,通过删除按钮将项目删除,然后重新创建时不要勾选任何选项,创建一个空的仓库,通过如下命令将本地项目推送到远程仓库:

cd existing_repo
git remote rename origin old-origin
git remote add origin https://xieyonghui.com/nick/web.git
git push -u origin --all
git push -u origin --tags
git