跳至主要內容

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-proxyopen in new window 原始地址前添加代理服务器 https://mirror.ghproxy.com/open in new window
备用服务器:GitHub 文件加速 (hunshcn.github.io)open in new windowGitHub 文件加速 (99988866.xyz)open in new windowGitHub 文件加速 - Moeyyopen in new window

GitMirror

Github 文件加速服务 - GitMirroropen in new window

  • 文件 在源网址前加上 https://hub.gitmirror.com/

  • RAWraw.githubusercontent.com 替换为 raw.gitmirror.com

  • GISgist.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网站下载加速

https://d.serctl.com/open in new window

自建服务

Cloudflare

gh-proxy: cf-worker版本部署open in new window
gaboolic/cloudflare-reverse-proxy: cloudflare反向代理open in new window
使用cloudflare制作GitHub“镜像站” - 知乎 (zhihu.com)open in new window
利用CloudFlare的Workers和Pages反代Github并缓存实现Github文件加速访问open in new window

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;
    }
}

nginx本地反代githubopen in new window


  1. 部分克隆(Partial clone)介绍open in new window ↩︎

  2. 部分克隆 - GitLab文档open in new window ↩︎

  3. Git clone仓库的一个子目录open in new window ↩︎

  4. How do I clone a subdirectory only of a Git repository?open in new window ↩︎

  5. git clone 所有分支,并push到另一个repo 转载open in new window ↩︎

  6. 迁移git项目到另一个仓库(保留所有分支、标签、历史记录)open in new window ↩︎

  7. jsDelivropen in new window ↩︎