Git 自动转成 SSH

109 字
1 分钟
Git 自动转成 SSH
  1. 1Git 常用配置与仓库管理
  2. 2Git 自动转成 SSH本文

GitHub 的 HTTPS 时常连不上,SSH 走 22 端口要稳得多。与其每次 clone 都手动改地址,不如让 git 自动把 https://github.com/ 前缀改写成 SSH 形式。

配置#

Terminal window
git config --global url."git@github.com:".insteadOf "https://github.com/"

配好之后,git clone https://github.com/user/repo.git 实际走的是 SSH,前提是本机公钥已经加到 GitHub 账号里。

验证与撤销#

Terminal window
# 查看当前生效的 url 改写规则
git config --global --get-regexp "url\."
# 撤销
git config --global --unset url."git@github.com:".insteadOf

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Git 自动转成 SSH
https://dongyue.org/posts/1/
作者
冬月
发布于
2026-09-08
许可协议
CC BY-SA 4.0

评论区

文章目录