2017-03-15 76 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')' –

相關問題