Home >Development Tools >git >Does git create a branch from master or dev?

Does git create a branch from master or dev?

WBOY
WBOYOriginal
2023-05-20 13:03:371732browse

Git creates branches from Master or Dev?

When we use Git to manage code, branching is a very important concept. Using branches can ensure the stability of the code while developing, and can also facilitate team collaboration. But when creating a branch, a very common question is: Should you create a new branch from the Master branch or the Dev branch?

In this article, we will explore this issue, understand which branch should be created from, and why.

First of all, we need to understand the role of the Master branch and the Dev branch. The Master branch is the main branch of Git and the most stable branch. Code on the Master branch should be deployable and should not contain any untested or incomplete features. This ensures the stability and security of the production environment.

The Dev branch, as the development branch of Git, is an environment used to develop new features or fix bugs. The code on the Dev branch may not necessarily be stable, but it should be fully functional and tested code. The Dev branch also facilitates team collaboration because each developer can create their own branch on it to perform relatively independent development work.

Next, let's consider which branch should serve as the basis for the new branch. Generally, we should create new branches from the Dev branch. This is because the new branch created from the Dev branch contains all the latest code and features, and these features have also been tested.

However, in some cases, it also makes sense to branch from the Master branch. For example, if we need to create a branch to fix a bug, we can create a new branch from the Master branch. This is because the branch where the bug is fixed should be built based on the code that has been released to the production environment, that is, the code on the Master branch.

Also, if we are not sure which branch to create a new branch from, we can consider creating a new branch from the latest shared branch (such as the latest merge request). This ensures that we build new branches based on the latest shared code, reducing the chance of merge conflicts.

In summary, creating a new branch from the Dev branch is a better choice. This way we can build new branches based on the latest testable code, ensuring that our code has the latest functionality and stability. However, in some cases, it also makes sense to create a new branch from the Master branch, such as when fixing a bug. If we are not sure which branch to create a new branch from, we can consider creating a new branch from the latest shared branch.

In short, when creating a new branch, we should carefully consider and choose the correct branch to create. This ensures our code has the latest functionality and stability, while also improving team collaboration and the security of our production environment.

The above is the detailed content of Does git create a branch from master or dev?. 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