查看: 86|回覆: 1

git 设置和取消指定域名代理 - git config proxy

[複製鏈接]

1

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2012-4-12
發表於 2019-12-10 15:34:00 | 顯示全部樓層 |閲讀模式

git config

Firstly - Check

  • Check if U have global .gitconfig file

  • 检查是否有全局 .gitconfig 文件

  • Usually global .gitconfig will be created in directory /Users/yourAccountName

  • 通常情况下全局的.gitconfig文件会在文件夹 /Users/你的用户名下

  • Such as mine, it is being /Users/robingao

  • 我的是/Users/robingao(Just because my account name of my MBP is robingao)

Secondly - Show the code

  • If not exist, it just indecated that you had never config global git configuration.But it happened rarely.

  • 如果不存在,说明你从来没有配置过git的全局配置。但,这种情况极少

  • U can just created it by opening your terminal in spotlight(shotcut: ⌘ + space), and copy and run(just tap ↩︎ button) the code below

  • 你可以通过聚焦搜索来打开终端(快捷键:⌘ + 空格),复制并运行(回车)下面的代码

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

Thirdly - Description

  • U can open the .gitconfig by clicking it, and U can see the text below what was generated just now.
  • 你可以打开.gitconfig文件来查看,会显示刚刚生成的如下文本
[http "https://github.com"]
	proxy = http://127.0.0.1:1080
  • The proxy works as a medium between https://github.com and your device

  • 代理在你的设备和https://github.com之间充当媒介

  • U must check if your proxy port is 1080. If not, change it into yours.

  • 查看你的代理端口是否是1080,如果不是,改成你自己的。

Forthly

  • U wanna got all connection through git mediated by your proxy, U might just code http.proxy.Whole code is shown below
  • 如果你想所有的git命令都走代理,只需要写http.proxy,完整代码如下
git config --global http.proxy http://127.0.0.1:1080

Fifthly

  • It is not the end. U have to run another code below to ensure https connection go through proxy
  • 还没结束。还需要再运行下面的代码,确保https的连接也走代理
git config --global https.https://github.com.proxy https://127.0.0.1:1080

OR(或者)

git config --global https.proxy https://127.0.0.1:1080

------------------------- MAGIC CODE AREA / 完整代码 -------------------------

  • If U just wanna got configured right now, and have no time to understand it, just run the magic code behind
    如果你就想配置完就完事了,没时间搞懂,那就直接复制运行下面的代码
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080

OR JUST GITHUB PROXY

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

------------------------ SOCKS5 HERE / socks5 代理 ---------------------------------

git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080

OR JUST GITHUB PROXY

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

----------------------- UNSET PROXY / 重置代理 --------------------------------

git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

OR

git config --global --unset http.proxy
git config --global --unset https.proxy

ANOTHER WAY

  • U might open .gitconfig and type the configuration text just like
  • 你也可以直接打开.gitcofig文件,直接写下文本,像这个
[http "https://github.com"]
	proxy = http://127.0.0.1:1080
[https "https://github.com"]
	proxy = https://127.0.0.1:1080

END

回覆

使用道具 舉報

0

主題

2092

回帖

1萬

積分

琼殿精英

金币
10581
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2011-10-11
發表於 2026-6-13 12:18:41 | 顯示全部樓層
看到楼主的分享了,非常感谢!这帖子整理得很详细,对于经常需要拉取GitHub代码的同学来说太实用了!
总结一下关键点:

  • 设置GitHub专用代理:git config --global http.https://github.com.proxy http://127.0.0.1:1080
  • 设置全局代理:git config --global http.proxy http://127.0.0.1:1080
  • 取消代理:git config --global --unset http.proxy

温馨提示:端口1080是常见的代理端口,但具体还要看你本地代理软件的实际端口是多少哦~如果端口不对改一下就行。

上次我就是因为没注意端口,白折腾半天

圆梦公社果然是技术氛围浓厚!感谢楼主的分享,已收藏备用~

对了,如果是SOCKS5代理的话,把http://改成socks5://就可以了,帖子也写得很清楚,赞一个!👍
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

圆梦公社,专注于为全球华人提供纯粹技术交流的地方,请勿发布任何政治及违法的言论。如有相关侵权、举报、投诉及建议等,请发 E-mail:dzh188@hotmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部