一、fetch first错误
原因:远程有文件,本地没有,故而无法push文件到远程;有时可能是远程文件新,本地文件旧(按照时间顺序)。
log:运行命令和log
$ git push origin master
To git@github.com:AntonioSu/learngitWindows.git
! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github.com:AntonioSu/learngitWindows.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 pull
二、git fatal: remote origin already exists错误
原因:此错误是因为已经存在了远程分支
log:运行命令和log
$ git remote add origin git@github.com:AntonioSu/learngitWindows.git
fatal: remote origin already exists.
解决方案:通过以下命令删除远程分支
$ git remote rm origin
三、non-fast-forward错误
原因:git仓库已经有一部分代码,不允许直接覆盖
log:
解决方案:
1.git pull
$ git pull #就是先把线上的代码和本地合并
$ git push
2.git push
$ git push -f
四、pre-receive hook declined错误
错误原因:无法git push是因为对应的分支权限为protected,只有项目的管理员或者项目的管理员指派的具有相应权限的人才能进行push。
log:
解决方案:
方案一:
找到仓库的Settings->Repository->Protected Bracnches->Unprotect
方案二:
新建分支而后融合到master分支