Files
AgentScript/github操作指南.md
T
HenryandClaude Code 26e13ff032 feat: Agent 工作区初始提交(源码+文档+Skills)
包含 CodeAgent 前后端源码、SKILLS、MCP、demo 代码与工作区文档。
排除依赖缓存、运行数据、备份与二进制附件,规则见 .gitignore。

Co-Authored-By: Claude Code <[email protected]>
2026-11-13 13:48:41 +08:00

3.6 KiB

一、新建 GitHub 空仓库(获取仓库地址)

  1. GitHub 主页右上角,点击 + 号按钮 → New repository

  2. 填写仓库信息:

    • Repository name:项目名,如jetrun_iot / agent(和本地文件夹对应)
    • Description(可选):项目描述,可留空
    • 仓库可见性:勾选 Public
    • ❗重要:不要勾选 Add a README file / Add .gitignore/ Add license(保持仓库为空,否则推送会冲突)
  3. 点击底部 Create repository 创建仓库

  4. 创建成功后,页面绿色按钮

    Code
    

    → 选择 HTTPS,复制仓库地址,示例:

    https://github.com/SweetieHenry/jetrun_iot.git
    

提示:A、B 两个项目需要分别创建 2 个独立仓库,不可混在同一个仓库。

二、生成 PAT (Classic) 个人访问令牌

  1. 右上角头像 SweetieHenry → 下拉菜单选择 Settings
  2. 页面左侧滚动到底部,点击 Developer settings
  3. 左侧菜单选择 Personal access tokens → Tokens (classic)
  4. 点击 Generate new token (classic)
  5. 令牌配置:
    • Note:备注,例如 windows-git-push(标记用途,方便后续识别)
    • Expiration:有效期,推荐选择 No expiration(永久有效)
    • Scopes(权限范围):只勾选 repo(完整仓库权限),其余全部取消勾选
  6. 拉到页面最下方,点击 Generate token 生成令牌
  7. ⚠️紧急提醒:生成页面会展示一长串字符串,立刻复制保存到记事本,一旦页面刷新,该令牌无法再次查看,丢失只能重新生成。

三、推送代码完整命令

3.1 首次推送(新仓库)

# 1. 进入项目目录
cd D:\Agent\agent

# 2. 配置代理(Clash 用户,只需执行一次)
git config --global http.proxy http://127.0.0.1:7897
git config --global https.proxy http://127.0.0.1:7897

# 3. 初始化 Git(只需一次)
git init -b main

# 4. 添加代码(三选一)
git add .                                  # 全部改动
git add backend frontend .gitignore        # 指定目录/文件

# 5. 提交
git commit -m "feat: 项目初始提交"

# 6. 关联远程仓库(只需一次,替换成你的仓库地址)
git remote add origin https://github.com/你的用户名/仓库名.git

# 7. 首次推送
git push -u origin main

3.2 日常推送(已初始化的仓库)

# 一句话版(最快)
cd D:\Agent\agent && git add . && git commit -m "feat: 你的描述" && git push

# 分步版
cd D:\Agent\agent
git add .                    # 或 git add 指定文件
git commit -m "feat: 你的描述"
git push

3.3 Commit Message 规范

git commit -m "feat: 新增XX功能"          # 新功能
git commit -m "fix: 修复XX问题"           # 修 Bug
git commit -m "refactor: 重构XX模块"      # 重构
git commit -m "docs: 更新XX文档"          # 文档
git commit -m "chore: 更新依赖/配置"      # 杂项

3.4 常见问题

问题 解决方案
Failed to connect to github.com port 443 配置代理(见 3.1 第 2 步)或重试
error: src refspec main does not match any 先 git commit 再 git push
! [rejected] main -> main (fetch first) 执行 git pull --rebase origin main 后重试推送
提示输入密码 填 PAT(不是 GitHub 账号密码)

3.5 安全提醒

  • .env(含 API 密钥)已在 .gitignore 中排除,永远不会入库
  • PAT 只在推送时使用,不要写入任何代码文件
  • PAT 泄露后立即到 GitHub 轮换:Settings → Developer settings → Personal access tokens