罗振宇和罗永浩长谈9个小时: 创业者八个重要关系
Git Flow is a branching model that provides a structured workflow for managing software development. 1. It uses two main branches: main for production-ready code and develop for integrating features. 2. Feature branches (feature/feature-name) are created from develop and merged back after completion. 3. Release branches (release/vX.X.X) are spawned from develop to prepare production releases, then merged into both main and develop, with version tagging. 4. Hotfix branches (hotfix/issue-name) are created from main to quickly address production bugs and merged back into both main and develop. This model ensures stable releases, supports parallel workflows, and enhances version control, making it ideal for teams with versioned releases, though it may be overly complex for continuous delivery environments.
Git Flow is a popular branching model designed to help development teams manage code changes efficiently, especially in projects with regular releases. Introduced by Vincent Driessen in 2010, it provides a clear structure for handling feature development, bug fixes, and releases—making collaboration smoother and reducing the risk of breaking production code.
At its core, Git Flow defines specific branches for specific purposes, each with a well-defined role and lifecycle. Here’s how it works.
Main Branches: main
and develop
Git Flow relies on two long-lived branches:
-
main
(ormaster
): This branch always reflects a production-ready state. Every commit onmain
is a potential release, often tagged with version numbers (e.g., v1.0.0). -
develop
: This is the main branch where integration of all features happens. It contains the latest delivered changes intended for the next release.
All feature work starts from develop
and eventually gets merged back into it.
Supporting Branches: Features, Releases, and Hotfixes
In addition to the main branches, Git Flow uses several types of short-lived branches for different workflows.
1. Feature Branches
- Purpose: Isolate development of new features.
-
Branch from:
develop
-
Merge back into:
develop
-
Naming convention:
feature/feature-name
You create a feature branch when starting new work:
git checkout -b feature/user-login develop
Once the feature is complete and tested, merge it back into develop
:
git checkout develop git merge feature/user-login git branch -d feature/user-login
This keeps ongoing development isolated and stable.
2. Release Branches
- Purpose: Prepare a new production release. This is where final polishing happens—bug fixes, documentation, version bumping.
- Branch from:
develop
- Merge back into:
develop
andmain
- Naming convention:
release/v1.2.0
When the team decides it’s time to release, a release branch is created:
git checkout -b release/v1.2.0 develop
During this phase, only minor fixes are allowed. No new features. Once ready:
git checkout main git merge release/v1.2.0 git tag -a v1.2.0 -m "Release version 1.2.0" git checkout develop git merge release/v1.2.0 # Bring changes (like version bump) back git branch -d release/v1.2.0
This ensures main
and develop
both have the correct updates.
3. Hotfix Branches
- Purpose: Quickly fix a critical bug in production.
- Branch from:
main
- Merge back into:
main
anddevelop
- Naming convention:
hotfix/critical-bug
If a bug is found in production, you don’t wait for the next release:
git checkout -b hotfix/login-bug main
After fixing and testing:
git checkout main git merge hotfix/login-bug git tag -a v1.2.1 -m "Hotfix login issue" git checkout develop git merge hotfix/login-bug git branch -d hotfix/login-bug
This gets the fix out fast and ensures it’s included in future development.
Why Use Git Flow?
- Clear roles: Everyone knows where to work and what each branch means.
-
Stable production: The
main
branch stays clean and release-ready. - Parallel workflows: Features, releases, and hotfixes can happen simultaneously without interference.
- Better version control: Tags and structured merges make rollbacks and audits easier.
That said, Git Flow adds complexity. For smaller teams or continuous delivery setups, simpler models like GitHub Flow might be more appropriate.
Git Flow isn’t the only way to manage branches, but it’s a solid choice for teams that release software in versions and need strong control over what goes live. With proper tooling (like Git extensions or CI/CD integration), it can streamline collaboration and reduce deployment stress.
Basically, it’s structure for sanity—especially when things get busy.
The above is the detailed content of An Introduction to the Git Flow Branching Model. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Packfile is an efficient mechanism used by Git to package, compress and transfer repository objects. When you execute gitpush, gitfetch or gitclone, what Git actually transmits is the packfile; 1. It is initially generated by loose objects through gitgc or gitrepack commands and stored in the .git/objects/pack/ directory; 2. The packfile not only contains object data, but also records the delta relationship between objects, and achieves rapid search with index file (.idx). 3. This design reduces the transmission volume and improves synchronization efficiency; 4. A large number of small packfiles may affect performance, and can be used through gitgc or git

To view Git commit history, use the gitlog command. 1. The basic usage is gitlog, which can display the submission hash, author, date and submission information; 2. Use gitlog--oneline to obtain a concise view; 3. Filter by author or submission information through --author and --grep; 4. Add -p to view code changes, --stat to view change statistics; 5. Use --graph and --all to view branch history, or use visualization tools such as GitKraken and VSCode.

To delete a Git branch, first make sure it has been merged or no retention is required. Use gitbranch-d to delete the local merged branch. If you need to force delete unmerged branches, use the -D parameter. Remote branch deletion uses the gitpushorigin-deletebranch-name command, and can synchronize other people's local repositories through gitfetch-prune. 1. To delete the local branch, you need to confirm whether it has been merged; 2. To delete the remote branch, you need to use the --delete parameter; 3. After deletion, you should verify whether the branch is successfully removed; 4. Communicate with the team to avoid accidentally deleting shared branches; 5. Clean useless branches regularly to keep the warehouse clean.

ToswitchGitbranches,firstupdatethelocalrepowithgitfetch,checkexistingbrancheswithgitbranchcommands,thenusegitcheckoutorgitswitchtochangebranches,handlinguncommittedchangesbycommitting,stashing,ordiscardingthem.WhenswitchingGitbranches,ensureyourlocal

To discard the modifications in the Git working directory and return to the state of the last commit, 1. For the modifications of the tracked files, use gitcheckout-- or gitcheckout--. Discard all modifications; 2. For new files that are not tracked, use gitclean-f to delete the files. If the directory is included, use gitclean-fd. Before execution, use gitclean-fd to preview the delete content; 3. If you need to reset all changes (including the temporary storage area and the working directory), use gitreset-hard. This command will reset the working directory and the temporary storage area. Be sure to operate with caution. These methods can be used individually or in combination to achieve the purpose of cleaning up the working directory.

To add a subtree to a Git repository, first add the remote repository and get its history, then merge it into a subdirectory using the gitmerge and gitread-tree commands. The steps are as follows: 1. Use the gitremoteadd-f command to add a remote repository; 2. Run gitmerge-srecursive-no-commit to get branch content; 3. Use gitread-tree--prefix= to specify the directory to merge the project as a subtree; 4. Submit changes to complete the addition; 5. When updating, gitfetch first and repeat the merging and steps to submit the update. This method keeps the external project history complete and easy to maintain.

Git hooks are used to automatically run scripts before and after commits, pushes and other operations to execute tasks. Specific uses include: 1. Run code checks or tests before submission; 2. Forced submission information format; 3. Send notifications after push. They help unify team specifications and reduce manual steps, such as preventing submissions when tests fail. Git hooks are located in the .git/hooks/ directory in the repository and are not shared by default. They need to be copied manually or used tools such as Husky for team collaboration. Writing a basic hook requires creating an executable file and naming the corresponding event, such as pre-commit, and writing logical judgments there to block or allow operations.

Soundstageafafileiititwittingchatcase, USEGITIZEADTORDOREMEVOME FROMARNINGAREAILACT.TOUNDACT Rungit Reset.ForPartialStialing, Usgit rests-PtointelavEevstehuncificisshunissehunissue
