D:\DevTools\Git
,不要用"新建文件夹"这种带空格的命名Git-2.xx.x-64-bit.exe
文件# 错误示例(绝对不要!)
C:\Program Files (x86)\Git新版\
# 正确示例
D:\DevEnv\Git\
Use Git and optional Unix tools from the Command Prompt
直接打开终端执行:
# 使用Homebrew安装(推荐)
brew install git
# 验证安装结果
git --version
如果提示command not found
,先安装Xcode Command Line Tools
打开Git Bash输入:
git config --global user.name "你的GitHub用户名"
git config --global user.email "注册GitHub的邮箱"
检查配置是否成功:
git config --global --list
看到类似输出就对了:
user.name=YourName
[email protected]
分步执行以下命令:
# 生成密钥(邮箱换成自己的)
ssh-keygen -t ed25519 -C "[email protected]"
# 查看公钥内容
cat ~/.ssh/id_ed25519.pub
把输出的内容完整复制到GitHub的SSH Keys设置页(Settings → SSH and GPG keys)
避免每次提示master
分支已过时:
git config --global init.defaultBranch main
症状:输入git --version
提示不是内部命令
急救方案:
C:\Program Files\Git\cmd
症状:GitHub提交记录显示奇怪的邮箱
病根诊断:
# 查看当前配置
git config --global --list
治疗方案:
重新运行用户信息配置命令,特别注意邮箱必须与GitHub注册邮箱一致!
自检步骤:
# 测试连接
ssh -T [email protected]
常见错误处理:
.ssh
目录权限是否为700在.gitconfig
文件中添加:
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
把常用命令缩短:
git config --global alias.st status
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.co checkout
避免Windows和Linux换行符冲突:
git config --global core.autocrlf input
git config --global core.eol lf
git pull → 修改代码 → git add → git commit → git push
git gc
优化仓库(重要提示)如果遇到本文未覆盖的疑难杂症,强烈建议运行git help
查看官方文档!毕竟Git是"世界上最先进的分布式版本控制系统"(Linus Torvalds亲封)
下次更新预告:《Git命令从入门到入土:50个你必须掌握的骚操作》,想提前解锁的读者老爷们评论区扣1~