Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the strategy of Git branch management

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "what is the strategy of Git branch management", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the strategy of Git branch management" article.

First, create a test project. 1. Build a new GitHub warehouse

Create a new repository on GitHub to demonstrate branch management, as shown in the following figure:

Click the "Create repository" button to create a new warehouse.

2. Upload the local warehouse project to GitHub2.1 and initialize the local warehouse

Enter the following command:

$git init

As shown in the following figure:

2.2. Add files to the staging area

Create a new file named branchdemo.txt under the newly created local repository and add it to the temporary storage area. Check the file status of the local repository first, as shown below:

The figure above shows that the newly created branchdemo.txt file is in an untracked state. You need to add to the staging area using the git add command:

2.3. Submit to the local warehouse

Submit the staging area file to the local warehouse, command:

$git commit-m "commit file"

As shown below:

2.4.Associate remote GitHub warehouses

Associate the local warehouse with the remote GitHub warehouse:

2.5. Push the local warehouse to the remote warehouse

Push the local project to the remote warehouse:

Then check the GitHub warehouse and find that the GitHub warehouse already has a local project:

2.6. View status

Enter the following command:

$git status

As shown in the following figure:

2. Management branch 1. Create a new branch of the local warehouse

Create a branch using the following command:

$git branch "New Branch name"

For example: create a branch named feature, as shown in the following figure:

2. Check whether the newly created branch is successful

Use the git branch command to view all the branches, as shown in the following figure:

You can see that the newly created branch has been successful, and the "*" sign indicates which branch it is currently in.

3. Switch branches

Switch branches using the following command:

$git checkout "Branch name"

As shown in the following figure:

4. View the current branch

As shown in the following figure:

You can see from the screenshot that the * sign is in front of feature, indicating that it is now in the branch of feature.

5. Push the created branch to the remote warehouse

The newly created local branch needs to be pushed to the warehouse of the remote GitHub, using the following command:

$git push origin feature

As shown in the following figure:

At this point, if you look at the GitHub branch, you will find that there are more feature branches:

6. Modify the file

Modify the branchdemo.txt file.

7. Submit the modified file to the temporary storage area

As shown in the following figure:

8. Submit to the local warehouse

As shown in the following figure:

9. Push to remote warehouse

The modified content of the local warehouse needs to be pushed to the remote warehouse, and enter the command:

$git push origin feature

As shown in the following figure:

10. View file status

Check the status of the file and check whether the file has been submitted successfully, as shown in the following figure:

Indicates that it has been submitted successfully.

11. Merge into master branch

Switch to the master branch before merging branches, as shown in the following figure:

After switching to the master branch, merge to the master branch using the merge command:

Push the local master branch to the remote master branch:

The above is the content of this article on "what is the strategy of Git branch management". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report