跳至主要內容

git设置和取消代理

loocao...小于 1 分钟默认git

快捷命令

git config --global https.proxy http://127.0.0.1:7890
git config --global https.proxy https://127.0.0.1:7890
git config --global --unset http.proxy
git config --global --unset https.proxy

仅为github.com设置socks5代理(推荐这种方式, 公司内网就不用设代理了, 多此一举):

git config --global http.https://github.com.proxy socks5://127.0.0.1:7890

修改~/.ssh/config方式

  1. https访问

仅为github.com设置socks5代理(推荐这种方式, 公司内网就不用设代理了, 多此一举):
git config --global http.https://github.com.proxy socks5://127.0.0.1:7890
其中1086是socks5的监听端口, 这个可以配置的, 每个人不同, 在macOS上一般为1086.
设置完成后, ~/.gitconfig文件中会增加以下条目:

[http "https://github.com"]
proxy = socks5://127.0.0.1:7890
  1. ssh访问

macOS系统,需要修改~/.ssh/config文件, 没有的话新建一个. 同样仅为github.com设置代理:

Host github.com
	User git
	ProxyCommand nc -v -x 127.0.0.1:7890 %h %p

如果是在Windows下,则需要个性%home%.ssh\config, 其中内容类似于:

Host github.com
	User git
	ProxyCommand connect -S 127.0.0.1:7890 %h %p
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.8