首页 > 解决方案 > Gitpython git push 推送失败时不会引发异常

问题描述

这似乎是一个已知问题,但我正在寻找解决方法。有人知道一个好的解决方法吗?

https://github.com/gitpython-developers/GitPython/issues/621

(Pdb) test = self.repo.remotes.origin.push(refspec=self.base_branch, progress=None, force=False)
2020-07-18 12:06:55,744|WARNING|guest|Error lines received while fetching: error: failed to push some refs to 'git@github.com:test/test.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.
(Pdb)```

标签: gitgitpython

解决方案


如果您的推送成功,您的本地引用origin/branch应该与branch.

您可以将其用作解决方法。


这不起作用的唯一情况是:如果您git push在本地branch与本地引用在同一点时触发origin/branch,而branch在实际远程上更新。

那就是:如果您在没有在分支上提交任何新内容的情况下进行推送。
100% 确定:您可以在推送之前检查是否branchorigin/branch,并采取相应措施(不要推送?)。


推荐阅读