繁体   English   中英

使用PyGit2仅克隆主分支

[英]Cloning only the main branch using PyGit2

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

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

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)

您的代码不仅获得了所有分支,而且还镜像了遥控器,并获得了远程跟踪分支,这可能会导致混乱的布局。

您已经设置了自己的refspec,因此需要设置refspec来下载默认分支。 如果您知道,可以更改代码以仅获取一个分支

remote = repo.remotes.create(name, url, "+refs/heads/master:refs/heads/master")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM