github代码快速批量下载

最近需要下载github代码发现速度出奇的慢,修改hosts效果也不明显,加上github代码内有些文件夹是以@XXXX形式的链接存在,需使用 --recurse-submodules 递归下载子文件夹。
好在发现https://hub.fastgit.org/ 包括国内一些镜像网站提供了一个国内快速下载github的解决方案。
用https://hub.fastgit.org/ 直接替换 https://github.com/可加快下载速度。
但是递归下载子模块时仍然需要链接到https://github.com/下载,导致子模块下载出错。
需要手动将下载后的项目文件夹中的“.gitmodule”文件内的
url = https://github.com/xxxx 修改文为:url = https://hub.fastgit.org/XXXX
单项目下载还可以接受,批量下载则比较麻烦,因此写了一个简单的批处理进行解决
注:此批处理默认按最新tag下载分支,通常情况下按tag下载分支都可以编译通过,按branch下载有时候不能编译通过,因此以最新tag为准下载分支。
fastgit.bat //单个调用
call_fastgit.bat // 批量调用
github_url //github项目链接地址
fastgit.bat 内容如下

@echo off
setlocal enabledelayedexpansion 
echo "Usage:fastgit.bat https://github.com/horsicq/stringsx64dbg.git"
echo %1
set remain=%1
set str=%remain:github.com=hub.fastgit.org%
echo "下载地址:%str%"
set toFind=git
set isFind=false
set now=
set next=
:loop
for /f "tokens=1* delims=./" %%a in ("%remain%") do (
	::echo %%b
	set now=%%a
	set next=%%b
	::pause
	if "%toFind%"=="%%b" (
		set isFind=true
		::echo %now% finded
		goto :finded
	)
	set remain=%%b
)
if defined remain goto :loop
:finded
git clone %str%
cd %now%
git tag 
git describe --tags --abbrev=0
for /f "delims=" %%i in ('git tag') do set new_tag=%%i
cd ..
rmdir /s /q %now%
echo 下载:git clone -b %new_tag% %str%
git clone -b %new_tag% %str%
cd %now%
SET modules= %~dp0%now%\.gitmodules
if exist %modules% (
	goto :gitmodules_replace)
) else (
	goto :no_gitmodules
)
 
:gitmodules_replace
echo "进入gitmodules_replace"
echo %modules%
for /f "delims=" %%I in (.gitmodules) do (
set "aa=%%I" 
set "aa=!aa:github.com=hub.fastgit.org!"
echo !aa!>>1.txt)
del .gitmodules
rename 1.txt .gitmodules
git submodule update --init --recursive
echo %now%" 下载成功!"
goto :exit

:no_gitmodules
echo .gitmodules 不存在
goto :exit
:exit
cd  ..
echo “退出子目录”

call_fastgit.bat 内容如下:

@echo off
setlocal enabledelayedexpansion 
for /f "delims=" %%a in (github_url.txt) do ( echo 开始下载:fastgit %%a&  fastgit %%a)
pause

github_url.txt内容如下:

https://github.com/xxxxx/aaaaa.git
https://github.com/xxxxx/bbbbb.git
https://github.com/xxxxxx/ccccc.git

运行call_fastgit.bat 即可开始下载

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值