简体   繁体   English

如何使用GitPython推送到远程仓库

[英]How to push to remote repo with GitPython

I have to clone a set of projects from one repository and push it then to a remote repository automatically. 我必须从一个存储库克隆一组项目,然后将其自动推送到远程存储库。 Therefore i'm using python and the specific module GitPython . 因此我使用python和特定模块GitPython Until now i can clone the project with gitpython like this: 到目前为止,我可以使用gitpython克隆项目,如下所示:

def main():
  Repo.clone_from(cloneUrl, localRepoPath)
  # Missing: Push the cloned repo to a remote repo.

How can i use GitPython to push the cloned repo to a remote repo? 我如何使用GitPython将克隆的repo推送到远程仓库?

it's all in the documentation : 这些都在文档中

repo = Repo.clone_from(cloneUrl, localRepopath)
remote = repo.create_remote(remote_name, url=another_url)
remote.push(refspec='{}:{}'.format(local_branch, remote_branch))

see also the push reference API . 另请参见推送参考API You can avoid the refspec setting if you set a tracking branch for the remote you want to push to. 如果为要推送的遥控器设置跟踪分支,则可以避免refspec设置。

It should work like this 它应该像这样工作

r = Repo.clone_from(cloneUrl, localRepoPath)
r.remotes.origin.push()

provided that a tracking branch was setup already. 只要已经设置了跟踪分支。

Otherwise you would set a refspec: 否则你会设置refspec:

r.remotes.origin.push(refspec='master:master')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM