首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PyGit2仅克隆主分支

使用PyGit2仅克隆主分支
EN

Stack Overflow用户
提问于 2016-01-11 06:28:14
回答 1查看 477关注 0票数 0

我想克隆一些远程存储库,但只检索主分支。

我的代码当前获取所有分支。

代码语言:javascript
复制
def init_remote(repo, name, url):
    # Create the remote with a mirroring url
    remote = repo.remotes.create(name, url, "+refs/*:refs/*")
    # And set the configuration option to true for the push command
    mirror_var = "remote.{}.mirror".format(name)
    repo.config[mirror_var] = True
    # Return the remote, which pygit2 will use to perform the clone
    return remote

pygit2.clone_repository(url, "../../clones/"+location, remote=init_remote)
EN

回答 1

Stack Overflow用户

发布于 2016-04-20 06:34:01

您的代码不只是获取所有分支,它还镜像遥控器,获取其远程跟踪分支,这可能会导致一些令人困惑的布局。

您已经设置了自己的refspec,所以您需要做的是设置refspec以下载默认分支。如果你知道它,你可以修改代码,只得到一个分支

代码语言:javascript
复制
remote = repo.remotes.create(name, url, "+refs/heads/master:refs/heads/master")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34711540

复制
相关文章

相似问题

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