HTTP形式
走http代理
1 2 3 4 5 6
| git config --global http.proxy "http://127.0.0.1:8080" git config --global https.proxy "http://127.0.0.1:8080"
git config -global http.https://github.com.proxy "http://127.0.0.1:8080"
|
走socks5代理
1 2 3 4 5
| git config --global http.proxy "socks5://127.0.0.1:1080" git config --global https.proxy "socks5://127.0.0.1:1080"
git config -global http.https://github.com.proxy "socks5://127.0.0.1:1080"
|
取消代理
1 2 3
| git config --global --unset http.proxy git config --global --unset https.proxy git config --global --unset http.https://github.com.proxy
|
脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #!/bin/bash
while getopts "p h r l" opt do case $opt in p) git config --global http.proxy 'socks5://127.0.0.1:1080'; git config --global https.proxy 'socks5://127.0.0.1:1080'; echo "成功配置git代理为:socks5://127.0.0.1:1080"
;; h) git config --global http.https://github.com.proxy socks5://127.0.0.1:1080 echo "成功配置github的git代理为:socks5://127.0.0.1:1080" ;; r) git config --global --unset http.proxy; git config --global --unset https.proxy; git config --global --unset http.https://github.com.proxy; echo "成功取消git代理" ;; l) git config -l ;; ?) echo "该脚本未定义该选项目" exit 1 ;; esac done
|
SSH形式
修改 ~/.ssh/config 文件(不存在则新建):
1 2 3 4 5 6 7 8 9
| Host github.com HostName github.com User git
|