开源项目贡献指南 (Git 命令行版)

1. 远程同步 (Fork & Clone)

  1. 在 GitHub 网页上点击目标仓库的 Fork 按钮。
  2. 你账号下 的仓库克隆到本地:
    git clone https://github.com
    cd 仓库名
  3. 关联原作者仓库(用于同步更新):
    git remote add upstream https://github.com

2. 开发分支 (Branching)

始终在独立分支开发,保持 main 分支纯净:

git checkout -b feat-my-feature

3. 代码提交 (Commit)

完成代码修改后,执行标准提交:

git add .
git commit -m "feat: 描述你的具体改动"

4. 保持同步 (Rebase)

在推送前,拉取原作者最新代码以避免冲突:

git fetch upstream
git rebase upstream/main

5. 推送与申请 (Push & PR)

  1. 将分支推送到你的远程仓库
    git push origin feat-my-feature
  2. 发起 PR:打开你 Fork 的 GitHub 页面,点击醒目的 "Compare & pull request" 按钮,填写说明并提交。

核心指令速查表

动作 命令 备注
关联原厂 git remote add upstream <url> 只需执行一次
新建分支 git checkout -b <name> 每次改动都要建新分支
同步原厂 git fetch upstream 提交前的必经步骤
推送代码 git push origin <name> 推送到自己的仓库

详情参考 GitHub 官方 Pull Request 文档