Codex + Git 开发环境配置指南(WSL版)
适用于:Windows + WSL + Codex CLI + Git
目标:构建稳定、高效、可扩展的工程化开发环境
一、Codex 环境配置(WSL)
1. 推荐架构
Windows(宿主)
├─ Codex Desktop(可选)
└─ WSL(Ubuntu)
└─ Codex CLI(主力)
📌 建议:
- 主要使用 CLI(更稳定)
- App 仅用于辅助(目前 WSL 支持不完善)
Codex CLI 在 Linux/WSL 环境下更稳定,官方推荐使用类似 Linux 的环境运行 (apidog)
2. 工作目录规范(必须)
bash
mkdir -p ~/workspace
cd ~/workspace
❗ 不要使用:
bash
/mnt/c/...
原因:
- IO 性能差
- 权限问题
- Git 状态异常
3. Codex 基础使用
bash
codex
建议流程:
bash
git status
git add .
git commit -m "checkpoint"
codex
结束后:
bash
git diff
git commit -am "codex changes"
👉 始终用 Git 做"安全兜底" (Lineserve Cloud)
4. 常见问题
❗ Codex 无法启动
bash
which codex
如果不存在:
bash
npm install -g @openai/codex
❗ 性能慢
- 检查是否在
/mnt/c - 更新 WSL:
bash
wsl --update
wsl --shutdown
5. 推荐工具链
bash
sudo apt install -y \
build-essential \
cmake \
git \
curl \
wget \
unzip \
ffmpeg
6. 工程化目录结构(推荐)
~/workspace/
├── project-a/
├── project-b/
├── tools/
└── skills/
7. Codex 使用建议(核心)
✔ 小任务开始
- "添加注释"
- "生成 .gitignore"
✔ 再做复杂任务
- "重构模块"
- "实现接口"
✔ 安全原则
- 永远 review diff
- 不要盲信自动执行
- 重要操作手动确认
二、Git 配置(WSL)
1. 基础身份配置
bash
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
2. 默认分支
bash
git config --global init.defaultBranch main
3. 换行符(WSL关键)
bash
git config --global core.autocrlf input
👉 避免 Windows / Linux 冲突
4. 中文与编码
bash
git config --global core.quotepath false
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding utf-8
5. 编辑器
VS Code
bash
git config --global core.editor "code --wait"
6. SSH(推荐)
bash
ssh-keygen -t ed25519 -C "your@email.com"
cat ~/.ssh/id_ed25519.pub
添加到:
- GitHub
- GitLab
测试:
bash
ssh -T git@github.com
7. Alias(效率提升)
bash
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm commit
git config --global alias.lg "log --oneline --graph --decorate --all"
8. Pull 策略
bash
git config --global pull.rebase true
👉 保持提交历史干净
9. Push 策略
bash
git config --global push.default simple
10. 凭证缓存(可选)
bash
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=7200'
11. 全局忽略文件
bash
touch ~/.gitignore_global
示例:
node_modules/
*.log
*.tmp
.vscode/
bash
git config --global core.excludesfile ~/.gitignore_global
12. WSL 特别注意(非常重要)
❗ 不要混用 Git:
错误:
- Windows Git 操作 WSL 项目
- WSL Git 操作 Windows 项目
正确:
| 项目位置 | 使用 Git |
|---|---|
| WSL | WSL Git |
| Windows | Windows Git |
三、最佳实践总结
Codex
- 在 WSL 内使用 CLI
- 项目放在 Linux 文件系统
- 每次操作前后用 Git 记录
- 小任务逐步推进
Git
- 使用 SSH(ed25519)
- 统一 LF 换行
- 使用 rebase 保持历史整洁
- 配置 alias 提升效率
四、推荐工作流(强烈建议)
cd ~/workspace/project
git pull
codex
# 完成后
git diff
git commit
git push
五、进阶方向(可选)
- Git Hooks(自动检查)
- CI/CD 自动部署
- Codex + Tools + Skills 自动化开发
- 多仓库管理(mono repo)
结论
✔ Codex CLI + WSL 是当前最稳定方案
✔ Git 是整个流程的"安全保障"
✔ 两者结合可以形成完整自动化开发体系