2017-03-15 36 views
0

假设我有一个名为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()创建一个远程对象,但它给我一个错误,因为远程已经存在。

回答

0

由于连接已经存在,您应该能够拉动。

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


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

感谢Arthur,您的代码有效。但我如何拉特定的分支? – Fengeey

+0

@PatrickYu从一个特定的分支,使用'o.pull('分支名称')' – janos

+0

@PatrickYu你也可以使用'repo.remotes.origin.fetch('branch_name')' –

相关问题