The Complexity of Git
Git is an excellent code management system that plays a vital role in team collaboration.
However, many teams use Git without understanding it, or beginners find Git not so much a great tool as something obscure and confusing, often encountering code conflicts. This is typical of those who only know three commands — git add, git commit, git push — and don’t understand Git workflow.
Git Workflow
Before explaining Git workflow, we should understand that team development follows a specific process — an agreed-upon convention that everyone buys into. Anyone who doesn’t follow this process will find their work very painful.
The same applies to Git.
Git workflow is also called Git flow. It’s a Git plugin that predefines the code commit process. All it does is combine a few common commands into an agreed-upon pattern. Yes, it’s simply a philosophy.
In other words: you don’t actually need to install anything to use Git flow.
The Philosophy of Git Flow
For projects that aren’t very large, simply agreeing on the following Git flow is sufficient:
master should only contain production code. You must not develop directly on the master branch; instead, develop on other designated, independent feature branches. Not committing changes directly to the master branch is also a common rule shared by other workflows.
develop is the base branch for any new development. When you start a new feature branch, this will be its foundation. Additionally, once a developed feature is merged into the develop branch, it should be tested. After passing tests, it waits to be integrated into the master branch.
feature/xxx branches only exist during development. Once development is complete and merged into the develop branch, they should be deleted.
The above is a very small and simple workflow that only involves basic development and testing, suitable for small teams and small projects.
If it’s a very large project or a development team of hundreds or thousands of people, you’d likely also need branches like pre-release, hotfix, and release to ensure stable code deployment.
An Example
To develop a new feature called hello_world, the first thing we need to do is check out a new branch from develop: feature/hello_world
git checkout -b feature/hello_worldAfter that, all code development for the hello_world feature will be committed to this feature/hello_world branch.
Once all feature development is complete, we merge this branch into the develop branch and then delete it:
# First switch to the develop branchgit checkout develop# Update develop code to avoid merge push conflictsgit pull# Merge the branchgit merge feature/hello_world# Delete the branchgit branch -d feature/hello_worldAt this point, all code is on the develop branch. Normally, it needs to go to a testing environment for further testing (all basic testing and bug fixes should be completed before merging into develop). Here, it’s mainly about testing stability and compatibility. Once testing passes, merge into the master branch for release:
# Switch to the master branchgit checkout master# Merge the develop branchgit merge developFinal Thoughts
Git flow is a workflow philosophy that makes team collaboration easier. The example above is just a simple illustration. Once you truly understand the workflow, you can customize it yourself — after all, every team is different.