1. 创建一个Repository
-
进入 GitHub 并登录。
-
点击右上角的 "+" 号,然后选择 "New repository"。
-
Repository name: 输入仓库名称。
-
选择 "Private" 以使仓库保持私密,或选择"Public" 公开代码。
-
(可选)勾选 Add a README file 以初始化仓库。
-
点击 Create repository。
2. 本地代码推送到 Repository
如果你的代码已在本地 Git 仓库中:
# 进入你的项目目录
cd /path/to/your/project
# 初始化 Git(如果尚未初始化)
git init
# 添加远程仓库
git remote add origin https://github.com/your-username/your-repo.git
# 如果远程仓库的README.MD 不在本地仓库,需先拉去远程仓库,与本地仓库合并
git pull origin main --rebase
# 添加所有文件
git add .
# 提交更改
git commit -m "Initial commit"
# 推送到 GitHub(如果 main 分支不存在,可能需要使用 -u 选项)
git branch -M main # 确保分支名称为 main
git push -u origin main