Git 指南
大约 2 分钟
Git 指南
部分克隆(Partial clone)
添加过滤 blob
对象 --filter=blob:none
,不自动检出--no-checkout
[1]
稀疏检出--sparse
[2] ,浅克隆--dpeth 1
[3] [4]
# 开启稀疏检出
git config core.sparsecheckout true
分支操作
[5]
将远端分支全部变成本地分支mkdir some_repo
cd some_repo
git clone --bare https://xxx.git .git
git config --unset core.bare
git reset --hard
[6]
检出所有分支for remote in `git branch -r | grep -v master `; do git checkout --track $remote ; done
将本地分支全部推到远端
git remote rename origin old_origin
git remote add origin https://github.com/your_name/yyy.git
git push -u origin --all
git push -u origin --tags
Github CDN
Proxy
GitHub Proxy
gh-proxy 原始地址前添加代理服务器 https://mirror.ghproxy.com/
备用服务器:GitHub 文件加速 (hunshcn.github.io)、 GitHub 文件加速 (99988866.xyz) 、GitHub 文件加速 - Moeyy
GitMirror
文件
在源网址前加上https://hub.gitmirror.com/
RAW
将raw.githubusercontent.com
替换为raw.gitmirror.com
GIS
将gist.githubusercontent.com
替换为gist.gitmirror.com
jsDelivr RAW 加速
https://cdn.jsdelivr.net/gh/<用户名>/<仓库名>@<发布版本号>/<文件路径>
[7]
备选域名
https://fastly.jsdelivr.net/gh/
https://gcore.jsdelivr.net/gh/
https://purge.jsdelivr.net/gh/
serctl网站下载加速
自建服务
Cloudflare
gh-proxy: cf-worker版本部署
gaboolic/cloudflare-reverse-proxy: cloudflare反向代理
使用cloudflare制作GitHub“镜像站” - 知乎 (zhihu.com)
利用CloudFlare的Workers和Pages反代Github并缓存实现Github文件加速访问
export default {
async fetch(request, env, ctx) {
const pathname = new URL(request.url).pathname;
const pathparts = pathname.replace(/^\/+|\/+$/g,'').split('/');
if(pathparts.length < 2) {
return new Response(`Page not found ${JSON.stringify(pathname)}`, {
status: 404
});
}
const targetUrl = 'https://github.com';
const response = await fetch(targetUrl + pathname, {
method: request.method,
headers: request.headers,
body: request.body
});
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: response.headers
});
},
};
Nginx
server {
listen 80;
server_name github.server.name;
location /{
proxy_pass https://github.com;
}
}
server {
listen 80;
server_name raw.github.server.name;
location /{
proxy_pass https://raw.githubusercontent.com;
}
}