目的
表題の通り。
pythonで以下のコマンドと等価な操作を実行したい。
git clone <git_repo> -b <branch>
解決策
GitPythonを利用して実現する場合以下の通り実行する。
git.Repo.clone_from(<git_repo>, <dest>, branch=<branch>)
例
ブランチの指定
GitPythonの’gh-pages'ブランチを'/home/ser/GitPython'にクローンする:
python
# !/usr/bin/env python
import git
git.Repo.clone_from('https://github.com/gitpython-developers/GitPython',
'/home/user/GitPython',
branch='gh-pages')
タグの指定
GitPythonの’1.0.1'タグを'/home/user/GitPython'にクローンする:
python
# !/usr/bin/env python
import git
git.Repo.clone_from('https://github.com/gitpython-developers/GitPython',
'/home/user/GitPython',
branch='1.0.1')