如何从上游仓库拉取某个分支

How to pull a certain branch from a upstream repository

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

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

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


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