Skip to content Skip to sidebar Skip to footer

Cloning Only The Main Branch Using Pygit2

I want to clone some remote repositories, but only retrieving the main branch. My code currently gets all of the branches. def init_remote(repo, name, url): # Create the remote

Solution 1:

Your code doesn't just get all the branches, it mirrors the remote, getting its remote-tracking branches as well, which can lead to some confusing layout.

You're already setting your own refspec, so what you need to do is set the refspec to download the default branch. If you know it you can change the code to get just the one branch

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

Post a Comment for "Cloning Only The Main Branch Using Pygit2"