0

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

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

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)
4

1 回答 1

0

您的代码不仅会获取所有分支,它还会镜像远程,还获取远程跟踪分支,这可能会导致一些混乱的布局。

您已经在设置自己的 refspec,所以您需要做的是设置 refspec 以下载默认分支。如果您知道,您可以更改代码以获得一个分支

remote = repo.remotes.create(name, url, "+refs/heads/master:refs/heads/master")
于 2016-04-19T22:34:00.527 回答