To upload a local project to a remote GitLab repository, start by making sure the project is tracked with Git.
If Git has not been initialized in the project yet, run:
git init
git config user.name "xxx"
git config user.email "xxx"
Then add the project files to the staging area:
git add .
Create the first local commit:
git commit -m "首次提交"
Next, connect the local repository to the remote repository you created on GitLab. Replace the URL below with the repository URL from your GitLab project:
git remote add origin https://gitlab.com/你的用户名/你的项目名.git
Once the remote is linked, push the local code to GitLab:
git push -u origin main
If your default branch is master instead of main, use git push -u origin master.
For a project that is already a Git repository, you do not need to repeat the initialization and commit steps. In that case, only the remote setup and push commands are required to link the project to the new GitLab repository and upload the code.