search
HomeDevelopment ToolsgitShare an elegant way to play git workflow

Share an elegant way to play git workflow

Jan 13, 2023 pm 03:44 PM
front endgitrear end

在开发中,不论是一个团队一起开发一个项目,还是自己独立开发一个项目。都少不了要和git打交道。面对不同的开发场景,或许每个团队都有自己的git工作流。这里,我想分享一下我的团队目前正在使用的基于gitlabgit工作流。一起交流一下。

规范化的git流程能降低我们的出错概率,也不会经常遇到git问题,然后去搜一堆git高阶用法。我们的这套git玩法儿,其实只要会基本的git操作就行了,然后规范化操作,基本不会遇到git问题,这样大家就可以将时间用于业务上。最终,希望大家研究git的时候是在感兴趣的时候,而不是遇到问题,紧急去寻找答案的时候

我们的这种git工作流玩儿法呢,主要是分为下面几个分支:

  • master分支   最新的稳定代码
  • vx.x.x分支   版本分支,x.x.x是此次开发的版本号。
  • feat-xxx分支 特性(新的功能)分支
  • fix-xxx分支  修复分支

上面的这些分支呢,就是我们在开发中需要经常去创建并使用的分支。下面详细说说每个分支代表的意思。

master分支代表的是最新的稳定版本的代码,一般是版本分支或者修复分支的代码上线后合并过来的。

feat-xxx分支表示的是为开发某个版本的某个新功能而创建的分支。

vx.x.x represents the version branch. This is the branch we create from master under the name of this version number before the start of each version, such as version number is 2.0.1, then the version branch is v2.0.1. Then wait until the new features of this version are developed in feat-xxx and pass the smoke test, then go to gitlab to submit a mr and merge it into this version on the branch. After each environment test passes, merge the code of the version branch into master, and then delete this version branch.

fix-xxx represents the repair branch. Usually when dealing with online problems, a branch named after the defect name is created. After the defect test passes, mrMerge to the master branch to

Note: There is a detail here that the commit information submitted by development on the feature branch is generally considered to be useless information. When merging to the version branch, merge it into a commit (since we are using gitlab to merge, so check when initiating the mr request squash option will be fine), and after the test is submitted, whether it is to fix bugs during the test process or to optimize the function, all commit will be retained. This purpose is a warning, because I hope that the most The good situation is that the test is launched immediately. Although it is difficult to achieve this goal, the commit information left behind can help us review the

functions of each branch as described above. , then let’s talk about how to do some classic scenarios we developed:

The first scenario: normal development iteration

We take this time we need to develop a 1.0.0 version as an example. There are two functional modules, one needs to add a button, and the other needs to add a form

sequenceDiagram
master->>v1.0.0: 从master切出 v1.0.0
master->>feat-add-button: 从master切出 feat-add-button
master->>feat-add-form: 从master切出 feat-add-button
feat-add-form->>feat-add-form: 开发完成
feat-add-button->>feat-add-button: 开发完成
feat-add-button->>v1.0.0: 在gitlab发起mr到v1.0.0,并合并所有commit
feat-add-form->>v1.0.0: 在gitlab发起mr到v1.0.0,并合并所有commit
v1.0.0->>v1.0.0: 提测
feat-add-button->>feat-add-button: 修复测试bug
feat-add-button->>v1.0.0: 将修复的 commit cherry pick到 v1.0.0
v1.0.0->>master: 在gitlab上mr到master,并将合并信息改成 v1.0.0

Share an elegant way to play git workflow

Through the above sequence diagram, you can see that we are about to start The version named a version branch v1.0.0, and also created two feature branches feat-add-button and feat- based on the two functions under this version. add-form, and then wait for the function development to be completed before initiating mr through gitlab (note that the mergecommit option must be checked here) to merge To v1.0.0, then the code of the v1.0.0 branch will start flowing from the dev environment to the production environment. Among them, if there is anything that needs to be fixed or optimized, the feature branch will be modified first, and then cherry pick will be moved to the version branch. After going online, delete the version branch and the following feature branches.

The code version managed through this process is very clear. This is a part of the intercepted master fragment.

Share an elegant way to play git workflow

There is another scene in the normal iteration process. That is, during the development process, PM suddenly came over and said that due to some kind of force majeure, a function needed to be cut off. At this time, if the code has not been tested yet, or the function is relatively simple, it is not too troublesome to deal with it. But if so, your function and the code of other colleagues have been tested, and some bugs have been fixed. The commits are all intertwined, especially the requirements that involve modifying many files, which will be very troublesome to deal with at this time. , not only do you have to look at other people's code, but you also have to be careful not to make mistakes in your own code. At this time, it is very simple in our process. Just delete the existing version branches, and then regroup the feature branches that need to be online. It can be seen that version branches are combined by feature branches, that is to say, version branches can be arbitrarily combined by different feature branches. This is more convenient to handle

The second scenario is online bug repair

We take the click event of a button that needs to be repaired online as an example

sequenceDiagram
master->>fix-button-click: 从master切出 fix-button-click
fix-button-click->>fix-button-click: 修复问题并测试
fix-button-click->>master: 从gitlab发起mr合并到master

In fact, the process here It’s not much different from the above, but what needs to be noted here is that when fixing online problems, one commit will be made for each bug, and the commits will not be merged when merging it into the master. And the merge information needs to be modified to this version number. For example, this time it is v1.0.1

The third scenario is multi-version parallel development

This scenario is no different from the normal iteration scenario, it just depends on whether you have multiple versions, so create The corresponding version branch is enough. Just follow the normal iteration process for each version branch.

Q&A

Q: Why are there no branches corresponding to the environment such as dev, test, etc., so that push and deployment can be achieved

A: Our process has given up using these Fixed branch. There are several reasons,

  • After the code is tested, from dev to test, or even to uat (pre-release) environment, if there are code changes in different environments, then in order to keep the code of these branches consistent, it is necessary Synchronizing the code to each environment branch is a bit troublesome. This problem does not exist with version branches. There is only one version branch, which can correspond to various environments.

  • Convenient for parallel development of multiple versions. Multiple version branches can be created, which is more convenient to deploy to different test environments during parallel development. If the modules between versions are not closely related, you can also test them in parallel.

  • Semantic. Version branches can be used to know which branches are currently under development through the branch name.

Q: How to deal with changes in the master branch

A: If there are changes in the master branch, merge them into your own functional branch in a timely manner to prevent conflicts with other members' codes If there is a conflict

Recommended study: "Git Video Tutorial"

The above is the detailed content of Share an elegant way to play git workflow. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:juejin. If there is any infringement, please contact admin@php.cn delete
Git and GitHub: Exploring Their Roles and FunctionsGit and GitHub: Exploring Their Roles and FunctionsMay 09, 2025 am 12:25 AM

The role and function of Git and GitHub in software development is to manage code and collaborative development. Git efficiently manages code versions through commit, branch and merge functions, while GitHub provides code hosting and collaboration tools such as PullRequest and Issues to improve team collaboration efficiency.

GitHub: Discovering, Sharing, and Contributing to CodeGitHub: Discovering, Sharing, and Contributing to CodeMay 08, 2025 am 12:26 AM

GitHub is the preferred platform for developers to discover, share and contribute code. 1) Find specific code bases through search functions, such as Python projects. 2) Create a repository and push code to share with developers around the world. 3) Participate in open source projects and contribute code through Fork and PullRequest.

Using Git with GitHub: A Practical GuideUsing Git with GitHub: A Practical GuideMay 07, 2025 am 12:11 AM

Git is a version control system, and GitHub is an online platform based on Git. The steps to using Git and GitHub for code management and team collaboration include: 1. Initialize the Git repository: gitinit. 2. Add files to the temporary storage area: gitadd. 3. Submit changes: gitcommit-m"Initialcommit". 4. Related to the GitHub repository: gitremoteaddoriginhttps://github.com/username/repository.git. 5. Push code to GitHub: gitpush-uoriginmaste

GitHub's Impact: Software Development and CollaborationGitHub's Impact: Software Development and CollaborationMay 06, 2025 am 12:09 AM

GitHub has a far-reaching impact on software development and collaboration: 1. It is based on Git's distributed version control system, which improves code security and development flexibility; 2. Through functions such as PullRequest, it improves team collaboration efficiency and knowledge sharing; 3. Tools such as GitHubActions help optimize the development process and improve code quality.

Using GitHub: Sharing, Managing, and Contributing to CodeUsing GitHub: Sharing, Managing, and Contributing to CodeMay 05, 2025 am 12:12 AM

The methods of sharing, managing and contributing code on GitHub include: 1. Create a repository and push code, and write README and LICENSE files; 2. Use branches, tags and merge requests to manage code; 3. Fork the repository, modify and submit PullRequest contribution code. Through these steps, developers can effectively use GitHub to improve development efficiency and collaboration capabilities.

Git vs. GitHub: A Comparative AnalysisGit vs. GitHub: A Comparative AnalysisMay 04, 2025 am 12:07 AM

Git is a distributed version control system, and GitHub is a Git-based collaboration platform. Git is used for version control and code management, while GitHub provides additional collaboration features such as code review and project management.

Git vs. GitHub: Understanding the DifferenceGit vs. GitHub: Understanding the DifferenceMay 03, 2025 am 12:08 AM

Git is a distributed version control system, and GitHub is an online platform based on Git. Git is used for version control, branch management and merger, and GitHub provides code hosting, collaboration tools and social networking capabilities.

GitHub: The Frontend, Git: The BackendGitHub: The Frontend, Git: The BackendMay 02, 2025 am 12:16 AM

Git is a back-end version control system, and GitHub is a front-end collaboration platform based on Git. Git manages code version, GitHub provides user interface and collaboration tools, and the two work together to improve development efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools