I have recently stumbled upon this thread, but have not found any solution, so I have brewed my own. It is better than nothing, neither optimal nor pretty, but at least it works:
# Clone master
repo = Repo.clone_from('https://github.com/user/stuff.git', 'work_dir', branch='master')
# Clone the other branches as needed and setup them tracking the remote
for b in repo.remote().fetch():
repo.git.checkout('-B', b.name.split('/')[1], b.name)
Explanation:
- Clone the master branch
- Fetch the remote branch names
- Checkout branches and create them as needed
PS: I think Gitpython has not got a built-in method to do this with clone_from
.
UPDATE:
no_single_branch=True
option in GitPyhton is equal to --no-single-branch
in git CLI (other 'valueless' arguments can also supplied with True
value)
repo = Repo.clone_from('https://github.com/user/stuff.git', 'work_dir', branch='master', no_single_branch=True)