要将本地项目推送到 GitLab 的新项目中
- 初始化本地仓库(如果项目尚未使用 Git 管理):bash
git init
git config user.name "xxx"
git config user.email "xxx" - 将文件添加到暂存区:bash
git add .
- 提交文件到本地仓库:bash
git commit -m "首次提交"
- 关联远程 GitLab 仓库:
(将下面的 URL 替换为你在 GitLab 上创建项目时得到的仓库 URL)bash
git remote add origin https://gitlab.com/你的用户名/你的项目名.git
- 将本地代码推送到 GitLab:bash
git push -u origin main
(如果你的默认分支是 master 而不是 main,使用git push -u origin master)
如果是已存在的 Git 仓库,只需执行步骤 4 和 5 即可关联并推送代码到新的 GitLab 仓库。