Clone with a specific branch / tag in GitPython

Purpose

As the title says. I want to execute an operation equivalent to the following command in python.

git clone <git_repo> -b <branch>

solution

When implementing using GitPython Execute as follows.

git.Repo.clone_from(<git_repo>, <dest>, branch=<branch>)

Example

Specifying a branch

Clone the'gh-pages' branch of GitPython to'/ 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')

Specifying tags

Clone GitPython'1.0.1'tag to'/ 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')

Recommended Posts

Clone with a specific branch / tag in GitPython
Stop an instance with a specific tag in Boto3
Sort dict in dict (dictionary in dictionary) with a specific key
Count specific strings in a file
Enumerate files with a specific extension
Save a specific variable in tensorflow.session
Generate all files with a specific extension
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Draw a heart in Ruby with PyCall
If branch depending on whether there is a specific element in the list
Note) Batch conversion of specific symbols contained in a character string with a dictionary
[Python] Get the files in a folder with Python
Draw a graph with Japanese labels in Jupyter
Delete data in a pattern with Redis Cluster
Start Django in a virtual environment with Pipenv
Create a virtual environment with conda in Python
Build a Django environment with Vagrant in 5 minutes
Get git branch name and tag name with python
Extract lines containing a specific "string" in Pandas
Work in a virtual environment with Python virtualenv.
Create a new page in confluence with Python
A story packed with absolute values in numpy.ndarray
Enter a specific value for variable in tensorflow
Configure a module with multiple files in Django
How to count numbers in a specific range
Get a row containing a specific element in np.where
Get the value of a specific key in a list from the dictionary type in the list with Python
[Python] Leave only the elements that start with a specific character string in the array
I wrote a CLI tool in Go language to view Qiita's tag feed with CLI
Python2 / numpy> Replace only a specific column in a file with column data from another file> numpy.c_
[Python] Draw a Qiita tag relationship diagram with NetworkX
How to convert / restore a string with [] in python
Train MNIST data with a neural network in PyTorch
I want to transition with a button in flask
Specific sample code for working with SQLite3 in Python
Playing with a user-local artificial intelligence API in Python
Extract elements other than a specific index with Numpy
Try embedding Python in a C ++ program with pybind11
I want to work with a robot in python.
A addictive point in "Bayesian inference experience with Python"
Output a character string with line breaks in PyYAML
Transit to the update screen with the Django a tag
I can't manipulate iframes in a page with Selenium
[Python] Delete by specifying a tag with Beautiful Soup
Run a Python file with relative import in PyCharm
Create a fake Minecraft server in Python with Quarry
Apply conda's env to a specific directory with pyenv-vertualenv
Recursively get the Excel list in a specific folder with python and write it to Excel.