对比
方式 | 位置 | 只代理GitHub代码 | git clone gh 效果 |
---|---|---|---|
ssh | ~/.ssh/config 配置 |
Host github.com HostName github.com User git ProxyCommand nc -v -x 127.0.0.1:7890 %h %p |
飞快 |
https | 终端输入 | git config --global http.https://github.com.proxy socks5://127.0.0.1:7890 |
飞快 |
使用理由
1 | git clone --depth=1 git@github.com:jerryc127/hexo-theme-butterfly.git |
浅拷贝git clone --depth=1 ref
速度确实快,但是版本回退是问题,在 GitHub
上 Pull requests
非常不方便,而ssh
全拷贝会方便进行git的操作,可是全拷贝速度奇慢,只能通过代理下载,下文有介绍https
。
依赖
1 | 代理 # telnet 127.0.0.1 7890 |
SSH
设置macOS代理
修改 ~/.ssh/config
文件(不存在则新建rm -rf ~/.ssh/config && touch ~/.ssh/config
):
1 | # 必须是 github.com |
从 GitHub 克隆代码
1 | git clone git@github.com:jerryc127/hexo-theme-butterfly.git |
Https
删代理
1 | git config --unset http.proxy # 系统 > 全局 > 当前 |
查全局所有代理
1 | git config --global --list |
proxy结果
1 | https.https://github.com.proxy=https://127.0.0.1:7890 |
删除proxy
1 | git config --global --unset http.https://github.com.proxy |
全局代理
我们使用git config http.proxy socks5://127.0.0.1:7890
只能当前仓库,适用于git push
或git pull
等。由于git clone
的是其他仓库,所以需要使用全局或系统设置,我选全局代理。
1 | git config --global http.https://github.com.proxy socks5://127.0.0.1:7890 # 只代理GitHub的git |
查询代理设置
1 | git config http.proxy |
显示socks5://127.0.0.1:7890
即可
从 GitHub 克隆代码
1 | git clone https://github.com/jerryc127/hexo-theme-butterfly.git # https |
参考
git官方文档:https://git-scm.com/doc
macOS设置git的ssh代理主要参考:https://gist.github.com/chuyik/02d0d37a49edc162546441092efae6a1
https://gist.github.com/chenshengzhi/07e5177b1d97587d5ca0acc0487ad677
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Ln's Blog!
评论