Git 代理的设置取决于要操作的仓库的协议类型.
使用 HTTP/HTTPS/FTP 协议的 repo
编辑~/.bashrc文件:
1 | export http_proxy='http://myproxy.example.com:1080/' |
执行source生效:
1 | source ~/.bashrc |
使用 SSH 协议的 repo (git@)
安装 socat:
1 | sudo apt update |
然后编辑~/.ssh/config:
1 | Host Match *,!xxx.xxx.xxx.xxx |
config文件的语法: Read more about SSH config files
yocto 代理
安装 socat:
1 | sudo apt update |
安装 oe-git-proxy
1 | wget http://git.yoctoproject.org/cgit/cgit.cgi/poky/plain/scripts/oe-git-proxy |
编辑~/.bashrc文件:
1 | export GIT_PROXY_COMMAND="oe-git-proxy" |
执行source生效:
1 | source ~/.bashrc |
为某个仓库跳过代理
切换工作目录到要跳过代理的仓库, 然后执行:
1 | git config --add remote.origin.proxy "" |
remote.origin里的origin为远程仓库的名字, 如果想设置其他远程仓库, 将其替换为响应的名字, 例如remote.upstream