最近将大部分的开发工具都由WinGet替换为scoop了,一切配置妥当后今天发现给GitHub提交代码时,需要重新验证账号,但通过浏览器认证后一直提示一个错误:fatal: ServicePointManager 不支持具有 socks5 方案的代理,我配置代理一般都是http_proxy,因为它兼容性更好,但此时出现的错误又的确是socks5的问题,想来是多年前配置的了,一直使用也没啥问题,后来我删除了credential中的github账号信息,又出现了这个问题。

解决方案

出现这个问题也比较容易解决,只需要查看下git config,看下都是哪里配置了socks5协议的代理。

1
git config --global --list 

输出如下:

1
2
http.https://github.com.proxy=socks5://127.0.0.1:1080
http.https://github.com.proxy=socks5://127.0.0.1:1080

将其覆盖一下即可,我本地监听端口是1080,一般默认的是7890,根据自己实际情况修改。

1
2
3
git config --global http.proxy 'http://127.0.0.1:1080'
git config --global https.proxy 'http://127.0.0.1:1080'
git config --global http.https://github.com.proxy 'http://127.0.0.1:1080'

GitHub账号配置

我本地是配置了ssh-key的,不过也有大量的https://的github项目,懒得一一修改了。直接在GitHub点击头像 -> settings -> Developer settings(最下面) -> Personal access tokens -> Tokens(classic)中,点击右上脚的Generate new token按钮,选择Generate new token(classic),创建新的Token,输出2FA密码后,权限只需要全选repo即可,有效期就一年吧。将生成的token作为GitHub的密码填入即可。

1
2
3
4
5
Username for 'https://github.com': xxx    
Password for 'https://xxx@github.com':
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 20 threads

Git其他配置优化

开启安全验证

因为以前公司的Git仓库都是自己签发的证书,所以我关闭了http.sslVerify,现在都是使用GitHub,索性就全部打开吧。

1
2
# 开启全局安全验证
git config --global http.sslVerify true

当然,以后可能还会使用局域网内部的git服务,那就到时候根据地址单独配置即可。

1
2
3
# 给内网地址关闭安全验证
git config --global http."https://10.254.32.11/".sslVerify false
git config --global http."http://10.40.60.22/".sslVerify false

美化log输出

你现在的 git log 应该是默认的黑白列表。既然用了 pwsh (PowerShell Core) 和图标字体,可以加一个酷炫的多彩 Graph 视图。

添加一个别名 git lg

1
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

性能和格式

1
2
3
4
5
6
7
8
9
10
11
# 1. 性能起飞:开启 fsmonitor
git config --global core.fsmonitor true

# 2. 路径支持
git config --global gui.encoding utf-8

# 3. 换行符处理(Windows 必备,防止拉取代码后全是修改)
git config --global core.autocrlf true

# 4. 开启更智能的合并策略
git config --global pull.rebase true