How to clone from specific branch from Git using Gitpython

假如想象 提交于 2019-12-19 04:05:22

问题


I tried to clone a repository from git using GitPython in python function. I used GitPython library for cloning from git in my python function and my code snippet as follows:

from git import Repo

Repo.clone_from('http://user:password@github.com/user/project.git', /home/antro/Project/')

It clones from master branch. How do I clone from other branch using GitPython or any other library is available to clone from individual branches? Please let me know.

I am aware of clone by mentioning branch in commandline using

git clone -b branch http://github.com/user/project.git


回答1:


just pass the branch name parameter, e.g. :-

repo = Repo.clone_from(
    'http://user:password@github.com/user/project.git',
    '/home/antro/Project/',
    branch='master'
)

see here for more info




回答2:


From toanant's answer.

This works for me with the --single-branch option

repo = Repo.clone_from( 'http://user:password@github.com/user/project.git --single-branch', '/home/antro/Project/', branch='master' )



来源:https://stackoverflow.com/questions/43520843/how-to-clone-from-specific-branch-from-git-using-gitpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!