初始化本地仓库

首先,你需要进入你的项目文件夹,并将其初始化为一个 Git 仓库。

1
2
3
4
# 进入你的项目目录
cd /path/to/your/project
# 初始化仓库
git init

设置用户名和邮箱

1
2
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱@example.com"

连接远程仓库

1
2
3
4
# 关联远程仓库 (将 <URL> 替换为你的仓库地址)
git remote add origin https://github.com/用户名/仓库名.git
# 验证关联情况
git remote -v

完整提交流程

1
2
3
4
5
6
7
# 添加文件到暂存区
git add .
# 提交到本地仓库
git commit -m "首次提交:初始化项目"
# 推送到远程仓库
git branch -M main
git push -u origin main
1