windows Git 环境配置指南

适用人员:首次在 Windows 上克隆 new-website 项目的开发者
GitLab 地址:https://git.yun-sk.com/common/new-website.git


第一步:安装 Git

  1. 下载地址:https://git-scm.com/download/win
  2. 选择 64-bit Git for Windows Setup 下载
  3. 双击安装包,全程默认选项,一路 Next
  4. 安装完成后,桌面右键出现 Git Bash Here 即成功

第二步:配置用户信息

打开 Git Bash,执行:

1
2
3
4
5
git config --global user.name "你的姓名"
git config --global user.email "你的邮箱@公司.com"

# 验证配置
git config --global --list

第三步:配置 GitLab 认证(二选一)

方式 A:HTTPS + 存储密码(推荐)

1
git config --global credential.helper manager

第一次 clone 或 push 时会弹出登录框,输入 GitLab 账号密码后自动保存,之后无需重复输入。


方式 B:SSH 密钥(更安全,适合长期使用)

① 生成 SSH 密钥

1
2
ssh-keygen -t ed25519 -C "你的邮箱@公司.com"
# 一路回车,使用默认路径和空密码

② 复制公钥内容

1
cat ~/.ssh/id_ed25519.pub

复制输出的全部内容。

③ 将公钥添加到 GitLab

  1. 登录 https://git.yun-sk.com
  2. 右上角头像 → Preferences(偏好设置)
  3. 左侧菜单 → SSH Keys
  4. 粘贴公钥 → 点击 Add Key

④ 验证连接

1
2
ssh -T git@git.yun-sk.com
# 显示 Welcome to GitLab, @xxx! 即配置成功

第四步:克隆项目

打开 Git Bash,进入目标目录后执行:

1
2
3
4
5
6
7
8
# 进入存放代码的目录(根据实际路径修改)
cd /d/Projects

# HTTPS 方式(配置了方式 A)
git clone https://git.yun-sk.com/common/new-website.git

# SSH 方式(配置了方式 B)
git clone git@git.yun-sk.com:common/new-website.git

第五步:安装依赖(本地运行项目)

如果只查看代码、提交修改,可跳过此步骤。

① 安装 Node.js 20 LTS

下载地址:https://nodejs.org/zh-cn/download → 选择 LTS 版本安装

② 安装项目依赖

1
2
3
4
5
6
7
cd new-website

# 前端依赖
npm install

# 后端依赖
cd server && npm install && cd ..

③ 启动本地开发服务

1
npm start
服务 地址
前端 http://localhost:5173
后端 http://localhost:3001
CMS 后台 http://localhost:5173/cms/login

日常操作速查

1
2
3
4
5
6
git pull                    # 拉取远端最新代码
git status # 查看当前改动状态
git add . # 暂存所有改动
git commit -m "修改说明" # 提交到本地
git push # 推送到远端
git log --oneline -10 # 查看最近 10 条提交记录

推荐工具

工具 用途 下载
VS Code 代码编辑器,内置 Git 图形界面 https://code.visualstudio.com
GitLens(VS Code 插件) 可视化 Git 历史、对比改动 VS Code 插件市场搜索 GitLens

安装 VS Code 后,打开项目文件夹,左侧源代码管理面板即可完成提交、推送等操作,无需记忆命令。