Home  >  Article  >  Development Tools  >  How to create a new branch and submit code in gitlab

How to create a new branch and submit code in gitlab

PHPz
PHPzOriginal
2023-04-10 09:41:054813browse

When using GitLab, creating a new branch and submitting code are very basic and necessary operations. The specific steps are described below.

Step 1: Create a new branch locally

First you need to create a new branch locally. You can use the following command:

git checkout -b 新分支名

This command will create a new branch and switch the current branch to the new branch.

Step 2: Push the branch to GitLab

After the new branch is created, you need to push the new branch to GitLab. You can use the following command:

git push --set-upstream origin 新分支名

This command pushes the new branch to GitLab and sets it as the default branch. If you need to push an existing local branch, you can use the following command:

git push origin 本地分支名:远程分支名

where "local branch name" is the existing local branch name, and "remote branch name" is the name of the remote branch that needs to be created.

Step 3: Submit the code

After you create a new branch locally and push it to GitLab, you need to submit the code on the new branch. You can use the following command:

git add .
git commit -m "提交信息"

This command will add all files in the current workspace to the staging area and submit changes to the new branch.

Step 4: Push the code to GitLab

At this time, you need to push the locally submitted code to GitLab. You can use the following command:

git push

This command will push the local code to GitLab. Modifications are pushed to the current branch on GitLab.

Summary

The above are the specific steps to create a new branch and submit the code. It should be noted that when pushing the branch or code to GitLab, you need to bind the user to the project first, that is, use The following commands:

git config --global user.name "用户名"
git config --global user.email "电子邮件地址"

These commands bind a user and email address to a GitLab account so that commits can be recorded.

The above is the detailed content of How to create a new branch and submit code in gitlab. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn