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

How to analyze the difference between fork and branch in git

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article is about how to analyze the difference between fork and branch in git. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Differences: 1, fork is a GitHub operation, you can clone a new copy of the repository, branch is a Git operation, you can open another branch; 2, fork operation gets a new code warehouse, while branch operation gets a new branch of code warehouse.

This article operating environment: Windows10 system, Git2.30.0 version, Dell G3 computer.

What is the difference between fork and branch in git

Fork

Fork, English translation is fork, verb form is bifurcation, as shown below, from left to right, one straight line becomes multiple straight lines

When transferred to the git repository, fork can represent the bifurcation and clone a new copy.

Contains all the contents of the original warehouse (that is, upstream repository, upstream warehouse), such as branch, Tag, submission

If you want to merge your changes into the original project, you can submit your submission back to the original warehouse through Pull Request.

Fork is not really a Git operation, but a GitHub operation.

In other words, there is no fork operation for native Git tools. Fork is a function proposed by online code hosting platforms such as GitHub, Code Cloud, and so on.

The role of fork is similar to when you see a very interesting project on the hosting platform and want to improve it yourself, and then you fork it (similar to cloning), and finally you change a very powerful function and want to push it to the original fork project, at this time you can pull request, once the other party has accepted your pull request, your code may appear in the original fork project.

Branch

Branch, translated as a branch, its function is simply to open another branch. Using a branch means that you can separate your work from the development main line so as not to affect the development main line.

Git handles branches in a lightweight way, creating new branches can be done almost instantly, and switching between different branches is just as convenient.

In our development, there is only one master branch by default.

You can create a branch through git branch, but it does not automatically switch to a new branch

You can switch to another testing branch via git checkout

For remote repositories, there is a master branch, also known as the trunk, by default. When you receive a new requirement, you can pull out a branch, modify the code on it without affecting the original trunk code, and then merge it into the trunk after the modification test is complete.

This is the very common content of Git branch management.

Difference:

Fork can only operate on the code warehouse, and fork does not belong to the command of git. It is usually used as an "operation" of the code warehouse hosting platform.

Clone is a command of git that downloads files from a remote code store to a local one, thus forming a local code store.

The branch feature is very similar to fork. Fork gets a new, own code warehouse, while branch gets a new branch of a code warehouse.

The above is how to analyze the difference between fork and branch in git. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, 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

Internet Technology

Wechat

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

12
Report