Community程式設計與開發github.com

lg0219/github-ghclone

解決中國大陸網路環境下 GitHub 存取慢、clone/fetch 斷線的加速方案。自動輪換 GitHub 加速前綴並附帶重試機制,配置 git 全域靜態加速與 ghclone 別名。

github-ghclone 是什麼?

這是一個專為在中國大陸網路環境下開發者設計的 AI 代理技能,用於加速 GitHub 的 git clone、fetch 等操作。其核心機制是將 `github.com` 的請求自動導向多個社區維護的「加速前綴(mirror proxy)」代理,當某一個前綴無法使用或連線中斷時,它會自動輪換到下一個,並對每個前綴進行多次重試,從而大幅提升成功率和穩定性。安裝後不僅會建立一個 `ghclone` 腳本(支援 CLI 和 git 別名),還會自動配置 git 的全域 `insteadOf` 規則,讓普通的 `git clone` 命令也能直接受益於加速。該技能適用於 Claude Code、Cursor 等支援自訂腳本的 AI 代理平台,開發者只需執行一鍵安裝腳本即可完成配置,並可隨時手動增減前綴列表以適應代理服務的變化。整體上,它提供了一個輕量、自動化且具備故障轉移能力的 GitHub 存取加速方案。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add lg0219/github-ghclone

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

GitHub GHClone - 國內 GitHub 加速技能

適用場景

當使用者在國內網路環境遇到以下情況時啟用:

  • git clone https://github.com/... 慢、卡住、Recv failure: 連接被對方重置、超時
  • 直連 GitHub 網頁 / API 不穩定或完全被牆(curl https://github.com 0 位元組)
  • 需要批量拉取 GitHub 倉庫、Release 檔案、raw 檔案

核心思路:把 github.com 的存取改走國內可直達的「加速前綴(mirror proxy)」,並對多個前綴做自動輪換 + 重試。單個前綴掛死時不卡死,自動換下一個。

一鍵安裝

# 把本倉庫 clone 下來(用任意可用前綴先拉本倉庫也行)
git clone https://gh-proxy.com/https://github.com/OWNER/github-ghclone.git
cd github-ghclone
bash scripts/install.sh
source ~/.bashrc   # 讓 ~/bin 生效

安裝後得到:

  • ~/bin/ghclone —— 可執行腳本(自動輪換 3 個前綴,每前綴重試 3 次)
  • git 全域靜態加速 url."https://gh-proxy.com/https://github.com/".insteadOf(普通 git clone 直接受益)
  • git 別名 gclone → ghclone

使用

# 方式一:直接呼叫腳本
ghclone https://github.com/owner/repo.git --depth 1

# 方式二:git 別名
git gclone https://github.com/owner/repo.git --depth 1

# 普通 git 命令(已被全域加速,無需別名)
git clone https://github.com/owner/repo.git

ghclone 會自動探測哪個前綴當前可用,成功即返回,全失敗才報錯。

手動配置(不想跑 install.sh 時)

  1. 下載腳本(本倉庫自帶 bin/ghclone),放到 ~/bin/ 並 chmod +x。
  2. git 全域靜態加速(任選一個当前可用的前綴):
    git config --global url."https://gh-proxy.com/https://github.com/".insteadOf "https://github.com/"
    
  3. git 別名:
    git config --global alias.gclone '!~/bin/ghclone'
    
  4. PATH:確保 ~/bin 在 PATH(追加到 ~/.bashrc):
    export PATH="$HOME/bin:$PATH"
    

更換 / 增刪前綴(某前綴掛死時)

加速前綴是社區維護的代理,時有時無,需要能輪換:

  • 改 ~/bin/ghclone(或本倉庫 bin/ghclone)裡的 PATS=(...) 陣列,增刪前綴。
  • 改 git 全域靜態前綴:
    # 換成新的可用前綴
    git config --global url."https://新前綴/https://github.com/".insteadOf "https://github.com/"
    # 清掉舊前綴
    git config --global --unset url."https://舊前綴/https://github.com/".insteadOf
    

驗證前綴是否可用

對每個前綴跑一次真實小倉庫探測(返回 commit hash 即為可用,0 位元組/報錯為不可用):

for p in https://gh-proxy.com https://ghfast.top https://ghproxy.net; do
  n=$(git ls-remote "$p/https://github.com/octocat/Hello-World.git" HEAD 2>/dev/null | head -1)
  echo "$p -> ${n:-不可用}"
done

已知可用前綴(2026-10 實測,隨時會變)

前綴用法
https://gh-proxy.comhttps://gh-proxy.com/https://github.com/owner/repo.git
https://ghfast.tophttps://ghfast.top/https://github.com/owner/repo.git
https://ghproxy.nethttps://ghproxy.net/https://github.com/owner/repo.git

直連 github.com 在國內通常 0 位元組(被牆),務必走前綴。前綴服務不穩定,ghclone 的重試邏輯就是為了應對這種「連接被對方重置」的瞬時故障。

局限與注意

  • 前綴代理是第三方社區服務,可用性、速度、存續時間不可控;若全部失效,需尋找新前綴替換 PATS。
  • 只加速 github.com 的 git 協定存取;objects.githubusercontent.com(Release 大檔案)等子域同理可用前綴包一層。
  • 合規提示:請確保使用符合當地法規的出網方式。

相關技能