加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Git通过GitPython推送

发布时间:2020-12-16 22:41:53 所属栏目:Python 来源:网络整理
导读:我在Python中使用此代码(使用“import git”): repo = git.Repo("my_repository")repo.git.add("bla.txt")repo.git.commit("my commit description") 现在我想推动这个提交.我已经尝试了很多但没有成功. Python命令应该与此Bash命令类似: git push origin

我在Python中使用此代码(使用“import git”):

repo = git.Repo("my_repository")
repo.git.add("bla.txt")
repo.git.commit("my commit description")

现在我想推动这个提交.我已经尝试了很多但没有成功. Python命令应该与此Bash命令类似:

git push origin HEAD:refs/for/master
最佳答案
您可以尝试以下方法.它可能会解决您的问题……

repo.git.pull('origin',new_branch)
repo.git.push('origin',new_branch)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读