我正在尝试找到使用gitPython拉取git存储库的方法。到目前为止,这是我从官方文档here中获取的内容。
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来执行拉操作,我如何才能做到这一点?谢谢。
发布于 2012-11-01 04:16:24
我通过直接获取repo名称来做到这一点:
repo = git.Repo('repo_path')
o = repo.remotes.origin
o.pull()发布于 2018-02-08 17:27:24
希望你正在寻找这个:
import git
g = git.Git('git-repo')
g.pull('origin','branch-name')拉取给定存储库和分支的最新提交。
发布于 2017-11-24 17:00:30
正如公认的答案所说,可以使用repo.remotes.origin.pull(),但缺点是它将真正的错误消息隐藏在它自己的通用错误中。例如,当DNS解析不起作用时,repo.remotes.origin.pull()会显示以下错误消息:
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显示了真正的错误:
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.'https://stackoverflow.com/questions/13166595
复制相似问题