下面给你一份Windows + macOS 通用版 Git 安装与完整配置教程,一步到位,新手也能直接照做。


一、下载安装 Git

Windows

  1. 官网下载:https://git-scm.com/download/win
  2. 一路 Next 默认安装即可(不用改选项)
  3. 安装完打开 Git Bash 或系统 cmd 测试:
    git --version
    
    出现版本号即成功。

macOS

  1. 打开终端,输入:
    git --version
    
  2. 如果没装,会自动弹出安装命令行工具,点安装即可。
  3. 或用 Homebrew 安装:
    brew install git
    

二、基础配置(必须做)

打开 Git Bash / 终端,执行下面两条命令:

1. 设置用户名(写你自己的)

git config --global user.name "你的名字"

2. 设置邮箱(和你代码平台一致,如 Gitee/GitHub)

git config --global user.email "你的邮箱@xxx.com"

3. 查看配置是否成功

git config --list

三、常用进阶配置(推荐)

1. 设置默认分支为 main

git config --global init.defaultBranch main

2. 解决 Windows 换行符问题

git config --global core.autocrlf true

3. 配置编辑器(可选)

VS Code:

git config --global core.editor "code --wait"

四、配置 SSH 密钥(推代码不用输密码)

1. 生成密钥

ssh-keygen -t ed25519 -C "你的邮箱@xxx.com"

一路回车,不用设密码。

2. 复制公钥

  • Windows Git Bash:
    cat ~/.ssh/id_ed25519.pub
    
  • macOS:
    pbcopy < ~/.ssh/id_ed25519.pub
    

3. 粘贴到代码平台

  • GitHub/Gitee → 设置 → SSH 公钥 → 粘贴保存

4. 测试连接

ssh -T git@gitee.com

或

ssh -T git@github.com

出现欢迎语即成功。


五、常用 Git 入门命令

git init                # 初始化仓库
git add .               # 添加所有文件
git commit -m "备注"    # 提交
git remote add origin 仓库地址
git push -u origin main
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐