本地代码推到远程时出现报错
! [rejected] xxx-> xxx(non-fast-forward)error: failed to push some refs to ‘ssh://idp-gitlab-ssh.dtyunxi.cn:2289/operation-wkd/vicutu-web-operation-mgmt.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.
分析错误原因:
报错的大致原因就是说由于本地库的代码和远程库代码没有同步导致无法提交合并,产生冲突导致无法push
解决方法
1.首先我们可以使用git pull拉取代码,再push上去,假如推成功则解决问题
git pull
git push origin xxx
2.假如方法一后还是不行,则使用下面方法,先从远端仓库拉去不相关历史,再推代码上去
//从远端仓库拉去不相关历史
git pull origin main --allow-unrelated-histories
//推送到远端main分支
git push origin xxx
使用第二种方法在一般代码不存在问题的情况下都能推送成功