#1.下载gitpython依赖包 pip install gitpython (官网 https://gitpython.readthedocs.io/en/stable/intro.html)

#2.代码实现

import git

# 远程url地址(这里加了.git),需要下载的git代码url地址放在这个list里面(即 清空remoteUrls 替换成自己的,格式:['xxx.git','yyy.git'])

remoteUrls = ['https://github.com/LZacking/XiMaLaYaTing.git','https://github.com/wushenjiang/XimalayaTest.git','https://github.com/Chuwenyi/ximalaya.git','https://github.com/defsoul-lin/Ximalaya.git']

for url in remoteUrls:

    #文件夹名字命名,由于很多git仓库的项目名相同,下载下来不容易区分,因此采用 作者名_项目名 的格式命名目标文件夹

    filename = '_'.join(url.split('/')[-2:])[:-4] #如果不加.git[:-4]切片就不要了,因为[-4]是去除".git"这4个字符的

    print(filename)

    git.Repo.clone_from(url=url, to_path=filename,branch='master',recursive=True)

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐