如何使用Gitpython从Git的特定分支进行克隆 [英] How to clone from specific branch from Git using Gitpython

查看:1047
本文介绍了如何使用Gitpython从Git的特定分支进行克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用python函数中的GitPython从git中克隆一个仓库。
我使用GitPython库从git中克隆了我的python函数和我的代码片段,如下所示:

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

from git import Repo

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

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

它从主分支克隆。我如何使用GitPython从其他分支进行克隆,或者有任何其他库可以从各个分支进行克隆?请让我知道。

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分支 http://github.com/user/project.git

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

推荐答案

只需传递分支名称参数,例如: -

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

请参阅此处更多信息

这篇关于如何使用Gitpython从Git的特定分支进行克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆