我找到了一个使用Bash脚本完成相同任务的Bash脚本。
使用GitPython创建存储库的完整备份,无法弄清楚如何在不必手动检出它们的情况下显示所有分支。
Repo.clone_from(repo, folder)
我正在使用这行代码在循环中复制所有存储库中的文件。
我找到了一个使用Bash脚本完成相同任务的Bash脚本。
使用GitPython创建存储库的完整备份,无法弄清楚如何在不必手动检出它们的情况下显示所有分支。
Repo.clone_from(repo, folder)
我最近偶然发现了这个帖子,但没有找到任何解决方案,所以我自己想出了一个。它不是最优的,也不太美观,但至少它能用:
# 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)
说明:
附注:我认为Gitpython没有内置方法可以使用clone_from
完成此操作。
更新:
no_single_branch=True
选项在GitPyhton中等同于git CLI中的--no-single-branch
(其他“无值”参数也可以使用True
值进行提供)。
repo = Repo.clone_from('https://github.com/user/stuff.git', 'work_dir', branch='master', no_single_branch=True)
for b in Repo.clone_from(repo, folder).remote[0].fetch():
print(b.name)