Home >Development Tools >git >What is the difference between fork and branch in git?
Difference: 1. Fork is a GitHub operation, which can clone a new copy of a warehouse; branch is a Git operation, which can open another branch; 2. The fork operation results in a new code warehouse , and the branch operation results in a new branch of the code warehouse.
The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.
What is the difference between fork and branch in git
fork
fork, English translation Come over is fork, and the verb form is to fork, as shown in the figure below, from left to right, a straight line becomes multiple straight lines
Go to the git warehouse, fork can represent forking, cloning a (warehouse ) The new copy
contains all the contents of the original warehouse (i.e. upstream repository, upstream warehouse), such as branches, tags, submissions
If you want to merge your changes into the original project , you can contribute your submission back to the original warehouse through Pull Request
fork is not actually a Git operation, but a GitHub operation
In other words, for the native Git tool, There is no fork operation. Fork is a function proposed by online code hosting platforms such as GitHub and Code Cloud.
The role of fork is similar to when you see an interesting project on a hosting platform and want to improve it yourself, then you fork it (similar to cloning), and finally you make a great change When the function comes out and you want to push it to the original fork project, you can pull the request. Once the other party accepts your pull request, your code may appear in the original fork project.
#branch
branch, translated as branch, its function is simply to open another branch. Using a branch means that you can move your work from the main development line Separate to avoid affecting the main line of development
The way Git handles branches is very lightweight. Creating a new branch can be completed almost instantly, and switching between different branches is equally convenient
In our development, there is only one master branch by default, as shown in the figure below:
You can create a branch through git branch, but it will not automatically switch to the new one. Go to the branch
You can switch to another testing branch through git checkout
For the remote warehouse, By default, there is a master branch, also called the trunk. 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 and testing are completed.
This is also a very common content of Git branch management.
Difference:
fork can only operate on the code warehouse, and fork is not a git command. It is usually used as an "operation" on the code warehouse hosting platform.
clone is a command of git. Its function is to download files from the remote code warehouse to the local, thereby forming a local code warehouse
branch features are very similar to fork. What fork gets is a new, own code warehouse, while branch gets a new branch of a code warehouse
Recommended learning: " Git tutorial》
The above is the detailed content of What is the difference between fork and branch in git?. For more information, please follow other related articles on the PHP Chinese website!