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

How to create a new branch and submit code in gitlab

PHPz
Release: 2023-04-10 14:07:01
Original
4887 people have browsed it

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 新分支名
Copy after login

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 新分支名
Copy after login

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 本地分支名:远程分支名
Copy after login

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 "提交信息"
Copy after login

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
Copy after login

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 "电子邮件地址"
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template