Codex + Git 开发环境配置指南(WSL版)

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 是整个流程的"安全保障"

✔ 两者结合可以形成完整自动化开发体系


相关推荐
未济2 天前
linux 配置环境变量
linux
傲世仙尊3 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
Winlifes3 天前
我给 Codex 做了一个 Git 面板:分支树、提交历史和工作区操作
git
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
_艾伦 耶格尔.3 天前
进程间通信
linux
AI职业加油站3 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
Liuqy-053 天前
Linux IO编程——静态库、动态库
linux
此冬歌咏3 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
彧azz3 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
-梅3 天前
linux(8) 软硬链接
linux·运维·服务器