首次使用 Git 需要配置身份信息。使用 SSH 密钥可以免密码推送代码。

本节要点

  • user.name 和 user.email 会记录在提交中。
  • init.defaultBranch 可以设置默认分支名。
  • ssh-keygen 生成 SSH 密钥。

代码示例

git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main

ssh-keygen -t ed25519 -C "[email protected]"
cat ~/.ssh/id_ed25519.pub