在 Windows 系统上使用 Git 拉取代码的步骤如下:
1. 安装 Git
- 下载 Git:
前往 Git 官网 下载 Windows 版安装包。 - 安装:
双击安装包,按默认选项完成安装(一路点击 “Next”)。
2. 配置 Git(首次使用需设置)
打开 Git Bash(安装后会在右键菜单或开始菜单中找到),运行以下命令配置用户名和邮箱:
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱@example.com"
3. 拉取代码(Clone 仓库)
方式一:HTTPS(推荐新手)
- 在 GitHub/GitLab 等平台找到项目地址,点击
Code
→ 复制 HTTPS URL(如https://github.com/用户名/仓库名.git
)。 - 在 Git Bash 中切换到目标目录(例如
D:\Projects
):cd /d/Projects
- 执行克隆命令:
git clone https://github.com/用户名/仓库名.git
方式二:SSH(需配置密钥)
生成 SSH Key(如果未配置过):
ssh-keygen -t ed25519 -C "你的邮箱@example.com"
生成的公钥默认在
~/.ssh/id_ed25519.pub
,复制内容到 GitHub/GitLab 的 SSH Keys 设置中。Clone SSH 地址(如
git@github.com:用户名/仓库名.git
):git clone git@github.com:用户名/仓库名.git
4. 常见问题
权限错误:
- HTTPS:检查网络或密码(GitHub 已禁用账号密码,需用 Personal Access Token)。
- SSH:确认公钥已正确绑定到平台。
中文路径乱码:
在 Git Bash 中运行: “`bash git config –global core.quotepath false
内容由零声教学AI助手提供,问题来源于学员提问