Overview
Pitfalls domestic teams often hit with Git: unstable GitHub access, CI/CD solutions copied from abroad that don't adapt well, and commit messages mixing Chinese and English with no convention. This skill provides acomplete Git workflow adapted to domestic platforms and team habits。
Core principles: The workflow serves team efficiency, not process for process's sake. Choose what suits the team's size; don't force-fit big-company solutions.
Domestic Git Platform Adaptation
Platform Comparison
| Feature | Gitee | Coding.net | JiHu GitLab | CNB | GitHub |
|---|---|---|---|---|---|
| Domestic access | Fast | Fast | Fast | Fast | Unstable |
| Free private repositories | Yes | Yes | Yes | Yes | Yes |
| CI/CD | Gitee Go | Coding CI | Built-in GitLab CI | Built-in (.cnb.yml) | GitHub Actions |
| Code review | PR | MR | MR | MR | PR |
| Artifact repository | Limited | Complete | Complete | Complete | Packages |
| Suitable scenarios | Open source/small teams | Medium-to-large teams | Enterprise private deployment | Cloud-native / Docker pipelines | International projects |
Gitee-specific configuration
# 设置 Gitee 远程仓库
git remote add origin https://gitee.com/<org>/<repo>.git
# Gitee 的 SSH 配置
# ~/.ssh/config
Host gitee.com
HostName gitee.com
User git
IdentityFile ~/.ssh/gitee_rsa
PreferredAuthentications publickey
# 同时推送到 Gitee 和 GitHub(镜像同步)
git remote set-url --add --push origin https://gitee.com/<org>/<repo>.git
git remote set-url --add --push origin https://github.com/<org>/<repo>.git
Coding.net-specific configuration
# Coding 的仓库地址格式
git remote add origin https://e.coding.net/<team>/<project>/<repo>.git
# Coding 支持的 SSH 地址
git remote add origin git@e.coding.net:<team>/<project>/<repo>.git
JiHu GitLab-specific configuration
# 极狐 GitLab 私有化部署常见地址格式
git remote add origin https://jihulab.com/<group>/<repo>.git
# 或者企业内部部署
git remote add origin https://gitlab.yourcompany.com/<group>/<repo>.git
CNB (Cloud Native Build)-specific configuration
# CNB 仓库地址(仅支持 HTTPS,不提供 SSH 协议)
git remote add origin https://cnb.cool/<org>/<repo>.git
# HTTPS 认证:用户名固定为 cnb,密码为个人访问令牌(Access Token)
# 在 CNB 平台 → 个人设置 → 访问令牌 中生成
git config credential.helper store
Workflow Selection
Option 1: Trunk-Based Development
Suitable for: Small teams (2-8 people), fast iteration, with comprehensive automated testing.
main ──●──●──●──●──●──●──●──●──●──
\ / \ / \ /
feat/x ●─● ●─● fix/y ●─●
(短命分支,1-2 天内合回)
Rules:
- The trunk (main) always remains in a releasable state
- Feature branch lifetime does not exceed 2 days
- Merge to trunk at least once per day
- Use Feature Flags to control the visibility of unfinished features
# 从 main 拉分支
git checkout -b feat/user-login main
# 开发完成后,rebase 到最新 main
git fetch origin
git rebase origin/main
# 提交 PR/MR,合并后删除分支
Option 2: Git Flow (classic branching model)
Suitable for: Medium-to-large teams, fixed release cadence (e.g., biweekly iterations), needing to maintain multiple versions.
main ──●────────────────●────────────── 生产环境
\ / \
release ●──●──●──●──● ●──●──●──●── 发布分支
\ /
develop ──●──●──●──●──●──●──●──●──●──●── 开发主线
\ / \ /
feat/x ●─● ●─────● 功能分支
\ /
fix/y ●─● 修复分支
Branch description:
main— Production environment code, only accepts merges from release and hotfixdevelop— Development mainline, feature branches are pulled from here and merged back hererelease/*— Release branch, pulled from develop, only bug fixes, no new featuresfeat/*— Feature branchhotfix/*— Emergency fix, pulled from main, merged back into both main and develop
Option 3: Simplified workflow commonly used by domestic teams
Suitable for: The actual situation of most domestic small and medium-sized teams.
main ──●──────●──────●──── 生产环境(受保护)
\ / \ /
dev ──●──●─●──●──●─●──── 开发/测试环境
\ / \ /
feat/x ●● ●● 功能分支
Rules:
mainBranch is protected, can only be merged via PR/MRdevBranch corresponds to the test environment, automatically deployed- Feature branches are pulled from
devand merged back intodev devAfter tests pass, merge intomainfor release
Branch Naming Conventions
Common Naming in Domestic Teams
# 功能分支
feat/user-login # 新功能
feat/JIRA-1234-order-refund # 关联任务编号
# 修复分支
fix/payment-callback # Bug 修复
fix/JIRA-5678-null-pointer # 关联 Bug 编号
# 发布分支
release/v2.1.0 # 版本发布
release/2024-03-sprint # 按迭代命名
# 紧急修复
hotfix/v2.0.1 # 线上紧急修复
hotfix/fix-login-crash # 描述性命名
# 个人分支(部分团队使用)
dev/zhangsan/feat-login # 个人开发分支
Naming Rules
- All lowercase, use
-to connect words (no underscores or camelCase) - Prefix clearly indicates the branch type:
feat/、fix/、hotfix/、release/ - Link the ID from the task management platform (if any):
feat/TAPD-12345-description - Moderate length, just enough to show the purpose of the branch
Chinese Commit Message Conventions
Chinese Version of Conventional Commits
<类型>(<范围>): <简要描述>
← 空行
<正文(可选)>
← 空行
<脚注(可选)>
Type List
| Type | Description | emoji (optional) |
|---|---|---|
| feat | New feature | ✨ |
| fix | Bug fix | 🐛 |
| docs | Documentation update | 📝 |
| style | Code formatting (does not affect logic) | 💄 |
| refactor | Refactoring (neither a new feature nor a bug fix) | ♻️ |
| perf | Performance optimization | ⚡ |
| test | Test-related | ✅ |
| build | Build system or external dependencies | 📦 |
| ci | CI/CD configuration | 👷 |
| chore | Other miscellaneous | 🔧 |
| revert | Revert | ⏪ |
Good commit messages
feat(购物车): 支持批量删除商品
- 新增全选/反选功能
- 删除操作增加二次确认弹窗
- 批量删除接口使用 POST /cart/batch-delete
关联需求:TAPD-12345
fix(支付): 修复微信支付在 iOS 16 上无法唤起的问题
原因:微信 SDK 8.0.33 版本在 iOS 16 上 Universal Links 校验逻辑变更,
导致 openURL 回调失败。
方案:升级 SDK 至 8.0.38,并更新 Associated Domains 配置。
Closes #567
Bad commit messages
# 太笼统
update code
fix bug
修改了一些东西
# 没有上下文
fix: 修复问题
feat: 新增功能
# 中英混杂无规范
fix:修复了一个bug,因为user login的时候会crash
CI/CD Platform Adaptation
Gitee Go
# .gitee/pipelines/pipeline.yml
name: 构建与测试
displayName: '构建与测试流水线'
triggers:
push:
branches:
include:
- main
- dev
stages:
- name: 测试
jobs:
- name: 单元测试
steps:
- step: npmbuild@1
name: install_and_test
displayName: '安装依赖并执行测试'
inputs:
nodeVersion: 20
commands:
- npm ci
- npm test
Coding CI
// Jenkinsfile(Coding CI 支持 Jenkinsfile 语法)
pipeline {
agent any
stages {
stage('安装依赖') {
steps {
sh 'npm ci'
}
}
stage('单元测试') {
steps {
sh 'npm test'
}
}
stage('构建') {
steps {
sh 'npm run build'
}
}
stage('部署到测试环境') {
when {
branch 'dev'
}
steps {
sh './scripts/deploy-staging.sh'
}
}
stage('部署到生产环境') {
when {
branch 'main'
}
steps {
sh './scripts/deploy-production.sh'
}
}
}
post {
failure {
// 企业微信/钉钉通知
sh './scripts/notify-failure.sh'
}
}
}
JiHu GitLab CI
# .gitlab-ci.yml
stages:
- test
- build
- deploy
variables:
NODE_IMAGE: node:20-alpine
# 使用国内镜像加速
NPM_REGISTRY: https://registry.npmmirror.com
单元测试:
stage: test
image: $NODE_IMAGE
script:
- npm config set registry $NPM_REGISTRY
- npm ci
- npm test
coverage: '/Lines\s*:\s*(\d+\.?\d*)%/'
构建:
stage: build
image: $NODE_IMAGE
script:
- npm config set registry $NPM_REGISTRY
- npm ci
- npm run build
artifacts:
paths:
- dist/
部署测试环境:
stage: deploy
script:
- ./scripts/deploy-staging.sh
only:
- dev
environment:
name: staging
部署生产环境:
stage: deploy
script:
- ./scripts/deploy-production.sh
only:
- main
environment:
name: production
when: manual # 生产环境手动触发
CNB(Cloud Native Build)
# .cnb.yml — branch-first 结构,直接指定 Docker 镜像跑流水线
main:
push:
- docker:
image: node:20
stages:
- npm ci
- npm test
- npm run build
pull_request:
- docker:
image: node:20
stages:
- npm run lint
- npm test
Features:
- Each pipeline independently specifies a Docker image, naturally cloud-native
- Supports
push/pull_requesttriggers - The same event can run multiple pipelines in parallel
stagesalso supports the expanded form of- name: xxx+script:; see the official documentation for complex scenarios
Comparison of Domestic Alternatives to GitHub Actions
| GitHub Actions Feature | Gitee Go | Coding CI | JiHu GitLab CI | CNB |
|---|---|---|---|---|
| Trigger conditions | triggers | Jenkinsfile triggers | only/rules | push / pull_request |
| Dependency cache | cache step | stash/unstash | cache | See the official documentation |
| Artifact storage | artifacts | Artifact repository | artifacts | See the official documentation |
| Environment variables | env | environment | variables | env |
| Secret management | Environment variable configuration | Credential management | CI/CD Variables | Access Token |
| Manual trigger | Manual run | Manual trigger | when: manual | Manual run on the page |
PR/MR Description Template
Chinese Template
Create a PR/MR template file in the repository:
Gitee: .gitee/PULL_REQUEST_TEMPLATE.md
Coding / GitLab: .gitlab/merge_request_templates/default.md
## 变更说明
<!-- 简要描述这次改动做了什么,解决了什么问题 -->
## 变更类型
- [ ] 新功能(feat)
- [ ] Bug 修复(fix)
- [ ] 重构(refactor)
- [ ] 性能优化(perf)
- [ ] 文档更新(docs)
- [ ] 其他:
## 关联信息
- 需求/Bug 链接:
- 设计文档:
## 改动范围
<!-- 列出主要改动的模块和文件 -->
## 测试情况
- [ ] 单元测试通过
- [ ] 手动测试通过
- [ ] 相关模块回归测试通过
## 测试方法
<!-- 描述如何验证这次改动 -->
## 影响范围
<!-- 这次改动可能影响哪些功能?是否需要通知其他团队? -->
## 部署注意事项
- [ ] 需要执行数据库迁移
- [ ] 需要更新配置文件
- [ ] 需要更新环境变量
- [ ] 无特殊注意事项
## 截图/录屏
<!-- 如果涉及 UI 变更,贴截图或录屏 -->
Common Git Configurations
Optimizations for Domestic Environments
# 设置用户信息
git config --global user.name "张三"
git config --global user.email "zhangsan@company.com"
# commit message 编辑器设置为 VS Code
git config --global core.editor "code --wait"
# 解决中文文件名显示为转义字符的问题
git config --global core.quotepath false
# 设置默认分支名
git config --global init.defaultBranch main
# 代理设置(如果需要同时使用 GitHub)
git config --global http.https://github.com.proxy socks5://127.0.0.1:7890
# NPM 使用国内镜像
npm config set registry https://registry.npmmirror.com
Common Configurations for .gitignore in Domestic Projects
# IDE
.idea/
.vscode/
*.swp
# 依赖
node_modules/
vendor/
# 构建产物
dist/
build/
*.exe
# 环境配置
.env
.env.local
.env.*.local
# 系统文件
.DS_Store
Thumbs.db
desktop.ini
# 国内平台特有
.coding/
Checklist
Before pushing code, confirm:
- The branch name complies with team conventions
- The commit message format is correct, and the type and scope are accurate
- The corresponding requirement/bug ID is linked
- The PR/MR description is complete
- The CI pipeline passes
- Relevant colleagues have been requested to review