GitHub Clones Hanging, pip Stalling, brew Spinning: One Guide to Fix Them All
[Hard to read on a phone — open this on a PC] With AI tools taking off, the command line is making a comeback.

[Hard to read on a phone — open this on a PC]
With AI tools taking off, the command line is making a comeback. More and more tools ship a CLI version — Claude Code, Codex, OpenCode, and so on.
Use the terminal long enough and you hit an awkward problem: even with a proxy running, the command line stays its raw self. GitHub clones stall, pip hangs, brew spins. It happens all the time.
That is the problem this post solves.
Option 1: Use domestic mirrors
You skip the overseas route and connect straight to a domestic mirror. It is the fastest option, but it takes configuration.
GitHub → Gitee
GitHub is unreliable from China, so the best move is to import the repo into Gitee first and clone from Gitee.
Go to gitee.com, click "Import repository from GitHub", paste in the GitHub URL, and seconds later you have a Gitee mirror. After that:
git clone https://gitee.com/your-username/repo.git
The import syncs automatically; no manual updates needed.
If you only need the repo temporarily and don't want to import it, there is a simpler trick: "--depth 1" pulls just the latest commit, at about one percent of the full repo's size:
git clone --depth 1 https://github.com/xxx/repo.git
pip with the Tsinghua mirror
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
The Alibaba Cloud mirror is another common domestic option:
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
If a package isn't on the mirror, retry with --no-cache-dir, or switch back to the official source for now:
pip install --no-cache-dir xxx
Anaconda and Miniconda work the same way:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config set show_channel_urls yes
npm with the Taobao mirror
npm config set registry https://registry.npmmirror.com
If you run into odd package dependency problems, install cnpm:
npm install -g cnpm --registry=https://registry.npmmirror.com
Then use cnpm install in place of npm install.
Homebrew with the Tsinghua mirror
# Replace brew.git
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# Replace homebrew/core.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# Replace bottles
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
The first brew install downloads the bottles; after that it's fast.
Option 2: Route the command line through a proxy
You have a proxy, but command-line tools don't use it by default, so git clone and npm install are still slow. You have to point them at it explicitly.
Confirm the proxy port first
Each tool uses a different port; the common ones are:
- Surge: 1080
- Clash: 7890
- ShadowsocksX: 1086
Go with whatever port your own client displays.
On a Mac you can also open Settings -> Network -> Wi-Fi, then open "Details" for the current Wi-Fi network and look at the "Proxies" section there — the port is listed inside.
Git through a proxy
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
If the proxy only offers an HTTP proxy rather than SOCKS5:
git config --global http.proxy http://127.0.0.1:1087
git config --global https.proxy http://127.0.0.1:1087
If you clone over SSH ([email protected]:xxx/repo.git), git config won't take effect, so add this to ~/.ssh/config:
Host github.com
ProxyCommand nc -X socks5 -x 127.0.0.1:1080 %h %p
npm through a proxy
HTTP proxy:
npm config set proxy http://127.0.0.1:1087
npm config set https-proxy http://127.0.0.1:1087
SOCKS5 proxy:
npm config set proxy socks5://127.0.0.1:1080
npm config set https-proxy socks5://127.0.0.1:1080
Homebrew through a proxy
export ALL_PROXY=socks5://127.0.0.1:1080
brew install xxx
If retyping it every time is a hassle, put it in ~/.bash_profile:
alias brew="ALL_PROXY=socks5://127.0.0.1:1080 brew"
How to choose between Option 1 and Option 2
Put simply: use a mirror whenever one exists, and fall back to the proxy when it doesn't.
A mirror needs no proxy, and you configure it once for good. A proxy speeds up all traffic, including tools that have no domestic mirror.
Use both and you have the most reliable combination.
A few common pitfalls
The port number isn't fixed
Some proxy clients pick a new port on every launch, so it's best to pin the SOCKS port to a fixed value in the client.
TUN mode vs. global mode
TUN mode routes all system traffic through the proxy, command-line tools included. But if TUN gives you trouble, only global mode gets the command line through — except then all traffic goes through the proxy and domestic services actually get slower. A "bypass mainland China" rule resolves that conflict.
SSH doesn't use the HTTP proxy
If you clone GitHub over SSH, you have to configure ~/.ssh/config separately, as described above.
One-line summary
Every network problem comes down to knowing which path your traffic takes. Send it down the right path and it's fast.