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 小时前
如何切换window-ubuntu双系统【方案二】
linux·运维·ubuntu
2501_927283582 小时前
荣联汇智助力天津艺虹打造“软硬一体”智慧工厂,全流程自动化引领印刷包装行业数智变革
大数据·运维·数据仓库·人工智能·低代码·自动化
HXDGCL3 小时前
矩形环形导轨:自动化循环线的核心运动单元解析
运维·算法·自动化
丑八怪大丑3 小时前
Java网络编程
linux·服务器·网络
橙子也要努力变强3 小时前
信号捕捉底层机制-机理篇2
linux·服务器·c++
楠枬4 小时前
Git 分支管理
git
Jinkxs4 小时前
LoadBalancer- 主流负载均衡工具盘点:Nginx / Haproxy / Keepalived 基础介绍
运维·nginx·负载均衡
秋94 小时前
MySQL 8.0.46 全平台安装与配置详解(Windows/Linux/macOS)
linux·windows·mysql
小康小小涵4 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python