NOTE

1.3 Git

Git 安装、SSH、用户配置、代理与 GitHub SSH 连接记录。

Developer Tools更新于 约 1 分钟读完historical

这是历史学习笔记,可能存在过时或不完整的理解。

1. 安装Git

2. 配置ssh

ssh.md

3. 配置Git

3.1. 用户名

git config --global user.name "<NAME>"
git config --global user.email "<EMAIL>"

3.2. 可选

3.2.1. 替换https为ssh

如果希望把 GitHub 的 HTTPS 地址统一改写为 SSH,可以使用:

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

原笔记中的 git:// / 邮箱形式不是 GitHub SSH remote 的正确写法。

3.2.2. HTTP代理

仅在确实需要本地代理时配置,例如:

git config --global http.proxy http://127.0.0.1:<PROXY_PORT>
git config --global https.proxy http://127.0.0.1:<PROXY_PORT>

不需要代理时应删除对应配置,而不是长期保留失效端口。

4. 查看Git配置

git config --global --list

也可以查看 ~/.gitconfig

[user]
    email = <EMAIL>
    name = <NAME>
[url "git@github.com:"]
    insteadOf = https://github.com/

代理等机器相关配置按实际环境添加。

5. Github

  1. 将 SSH 公钥(例如 ~/.ssh/id_ed25519.pub)添加到 GitHub。
  2. 测试连接:
ssh -T git@github.com
# 成功时会看到:
# Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

6. 参考

正在加载有帮助数量