2025-10-24    2025-10-24    349 字  1 分钟

The note is partly generated by “ChatGPT.”

The article “Proxy set, but ssh -T git@github.com still fails” explains that Git SSH cannot use an HTTP proxy and provides a solution. However, in my experience, even using that solution, network performance can be unreliable. Therefore, if you can use HTTPS for Git, I recommend switching from SSH to HTTPS directly. Below is the method to switch to HTTPS and configure a Personal Access Token (PAT) for authentication.

1️⃣ Ensure your Git remote uses HTTPS

Check your current remote:

1
git remote -v

If it shows something like:

origin  git@github.com:jzjizhe/MyAstroNvim.git (fetch)
origin  git@github.com:jzjizhe/MyAstroNvim.git (push)

Switch it to HTTPS:

1
git remote set-url origin https://github.com/jzjizhe/MyAstroNvim.git

Verify:

1
git remote -v

2️⃣ Generate a Personal Access Token (PAT) on GitHub

  1. Go to GitHub → Settings → Developer settings → Personal Access Tokens

  2. Click Generate new token (classic)

  3. Select repo permission

  4. Copy the token (you’ll use it instead of a password)


3️⃣ Configure Git credential helper

This stores your credentials securely so you don’t have to type them again.

Windows:

1
git config --global credential.helper manager-core

Linux / WSL:

  • Cache for 1 hour (memory):
1
git config --global credential.helper cache
  • Or store permanently (plaintext, not recommended for multi-user machines):
1
git config --global credential.helper store

4️⃣ Push / Pull and enter credentials once

The first time you push:

1
git push

Git will prompt for:

  • Username: jzjizhe

  • Password: <your PAT>

After this, the credential helper caches it, so future push/pull commands won’t ask again.


5️⃣ Optional: Configure proxy (if needed)

If you are behind a network proxy:

1
2
3
4
5
6
7
# HTTP proxy
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

# SOCKS5 proxy
git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890

Result:

  • Git over HTTPS works without repeated credential prompts.

  • Works behind most HTTP/SOCKS proxies.

  • No SSH key setup needed.