git 不能使用 https url 克隆到本地

1,152 阅读1分钟

Notes: 解决 git 不能使用 https url 克隆到本地

原先在本地及远端配置了 ssh key, 当我用 https 去克隆项目到本地时出现 400 错误, ssh 的正常

clone fatal return 400

本地检查全局配置也并未发现问题, 查一查 git 官方文档:

url.<base>.insteadOf

这个配置会将 base 重定向(rewrite)到后面配置的地址

# 打开 git 全局配置, 进入到 vi 模式
# git config --global --edit

# 配置全局
git config --global url.git@github.com:.insteadOf https://github.com/

# 配置后查看 .gitconfig 文件
cat ~/.gitconfig

.gitconfig 会出现如下配置

[url "git@github.com:"]
    insteadOf = https://github.com/

再试试 clone https url

git clone https url

Done~

参考链接