flowchart TD %% 核心概念铺垫(注释说明,不显示在流程图中) %% 工作区:本地编写代码的文件夹;暂存区:.git/index;本地仓库:.git 目录;GitHub:远程服务器仓库 start[开始] --> choice{仓库来源} %% 分支1:本地新建项目流程 choice -->|1. 本地新建项目| A[git init初始化本地仓库→ 创建 .git 目录本地仓库+暂存区] A --> B[工作区:编写/新增文件] B --> C[git add <文件>工作区 → 暂存区→ 记录文件快照到暂存区] C --> D[git commit -m暂存区 → 本地仓库→ 生成提交对象,记录版本历史] D --> E[git remote add origin <GitHub地址>本地配置:记录远程仓库别名+地址,无服务器交互] %% 分支2:已有远程仓库流程(克隆) choice -->|2. 已有远程仓库| F[git clone <GitHub地址>1. 本地:创建文件夹+初始化仓库2. 服务器:下载完整版本数据3. 自动关联远程origin→ 工作区生成最新文件] F --> C[git add <文件>工作区 → 暂存区→ 记录文件快照到暂存区] %% 远程同步流程(拉取→合并冲突→推送) E --> G[git pull origin <分支名>1. 服务器→本地:下载远程最新提交fetch2. 本地合并:远程分支→当前本地分支merge] F --> G G --> H{合并冲突?} H -->|是| I[手动解决冲突→ 工作区修正冲突文件] H -->|否| J[git push origin <分支名>1. 本地→服务器:上传本地新增提交2. 服务器:更新远程分支,同步版本] I --> D[git commit -m解决冲突,暂存区 → 本地仓库→ 完成合并提交] D --> J J --> s[流程结束,本地- GitHub 代码同步完成] %% 样式优化:按操作类型区分颜色 style A fill:#e1f5fe,stroke:#0277bd,stroke-width:1.5px,labelStyle:'font-size:12px' style F fill:#f3e5f5,stroke:#7b1fa2,stroke-width:1.5px,labelStyle:'font-size:12px' style C fill:#fff3e0,stroke:#ef6c00,stroke-width:1.5px,labelStyle:'font-size:12px' style D fill:#e8f5e8,stroke:#2e7d32,stroke-width:1.5px,labelStyle:'font-size:12px' style G fill:#ffebee,stroke:#c62828,stroke-width:1.5px,labelStyle:'font-size:12px' style J fill:#fce4ec,stroke:#ad1457,stroke-width:1.5px,labelStyle:'font-size:12px' style I fill:#fff8e1,stroke:#f57f17,stroke-width:1.5px,labelStyle:'font-size:12px'
![]()