如何从上游存储库中提取某个分支

时间:2017-03-15 22:38:57

标签: github gitpython

假设我有一个名为GitPython的本地git克隆。我能够使用gitpython提交和推送:

repo = Repo(D:\Dev\Gitpython)
print(repo.git.add("."))
print(repo.git.commit(m='my commit message'))
print(repo.git.push())

但是,如何使用gitpython从上游存储库中提取? 我尝试使用Repo.create_remote()创建一个远程对象,但由于远程已经存在,它会给我一个错误。

1 个答案:

答案 0 :(得分:0)

由于连接已经存在,您应该可以拉。

repo = git.Repo('repo_name')
o = repo.remotes.origin
o.pull()


o = repo.remotes.origin
o.fetch('branch_name')