首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用GitPython拉取远程存储库?

如何使用GitPython拉取远程存储库?
EN

Stack Overflow用户
提问于 2012-11-01 04:01:32
回答 4查看 35.9K关注 0票数 24

我正在尝试找到使用gitPython拉取git存储库的方法。到目前为止,这是我从官方文档here中获取的内容。

代码语言:javascript
复制
test_remote = repo.create_remote('test', 'git@server:repo.git')
repo.delete_remote(test_remote) # create and delete remotes
origin = repo.remotes.origin    # get default remote by name
origin.refs                     # local remote references
o = origin.rename('new_origin') # rename remotes
o.fetch()                       # fetch, pull and push from and to the remote
o.pull()
o.push()

事实上,我想在不重命名其原点(origin.rename)的情况下访问repo.remotes.origin来执行拉操作,我如何才能做到这一点?谢谢。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-11-01 04:16:24

我通过直接获取repo名称来做到这一点:

代码语言:javascript
复制
 repo = git.Repo('repo_path')
 o = repo.remotes.origin
 o.pull()
票数 43
EN

Stack Overflow用户

发布于 2018-02-08 17:27:24

希望你正在寻找这个:

代码语言:javascript
复制
import git
g = git.Git('git-repo')
g.pull('origin','branch-name')

拉取给定存储库和分支的最新提交。

票数 9
EN

Stack Overflow用户

发布于 2017-11-24 17:00:30

正如公认的答案所说,可以使用repo.remotes.origin.pull(),但缺点是它将真正的错误消息隐藏在它自己的通用错误中。例如,当DNS解析不起作用时,repo.remotes.origin.pull()会显示以下错误消息:

代码语言:javascript
复制
git.exc.GitCommandError: 'Error when fetching: fatal: Could not read from remote repository.
' returned with exit code 2

另一方面,像repo.git.pull()这样的using git commands with GitPython显示了真正的错误:

代码语言:javascript
复制
git.exc.GitCommandError: 'git pull' returned with exit code 1
stderr: 'ssh: Could not resolve hostname github.com: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.'
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13166595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档