Git Lecture 17 Git Collaboration

collaborative workflow

In team development, it is very common to use Git for collaboration. A collaborative workflow defines the rules and processes for how team members collaborate, commit, and review code. Here are a few common collaboration workflows:

centralized workflow

The centralized workflow is the easiest workflow and is suitable for small teams or individual projects. In this workflow, all developers commit code directly to the master branch.

Example directory structure:

- 主分支 (main)
    - feature-1
    - feature-2
    - hotfix-1

work process:

  1. Create a new feature branch from the master branch.
  2. Develop and commit on feature branches.
  3. When you're done developing, merge the feature branch into the master branch.
  4. If you need to fix a problem, you can create a hotfix branch and merge it into the main branch.

Feature Branch Workflow

The feature branch workflow is suitable for large teams or long-term projects. In this workflow, each feature is developed on its own branch and finally merged into the main branch.

Example directory structure:

- 主分支 (main)
    - feature-1
    - feature-2
    - hotfix-1

work process:

  1. Create a new feature branch from the master branch.
  2. Develop and commit on feature branches.
  3. When you're done developing, merge the feature branch into the master branch.
  4. If you need to fix a problem, you can create a hotfix branch and merge it into the main branch.

Fork workflow

The fork workflow is suitable for open source projects and multiple team collaboration scenarios. In this workflow, each developer will fork his own warehouse (origin) from the main warehouse (upstream), develop on his own warehouse, and then initiate a Pull Request to the main warehouse.

work process:

  1. Fork the main warehouse and create your own warehouse (origin).
  2. Clone your repository locally.
  3. Create a new branch from the main repository and sync it to the local repository.
  4. Develop and commit on a local repository.
  5. Initiate a Pull Request to the main warehouse, waiting for code review and merging.

branch management strategy

A good branch management strategy can improve the efficiency of teamwork and the stability of the code. Here are a few common branch management strategies:

Master branch protection strategy

The master branch protection strategy aims to protect the stability and reliability of the master branch. Under this strategy, only code that has undergone rigorous review and testing is merged into the master branch.

Strategy steps:

  1. All developers create their own branches from the master branch.
  2. Develop and commit on your own branch.
  3. When the development is complete, initiate a Pull Request.
  4. Code reviewers review the code and make necessary revisions and discussions.
  5. After passing the code review, merge the code into the master branch.

Feature Branching Strategy

A feature branching strategy is a strategy where each feature or feature is developed on a separate branch.

Strategy steps:

  1. Create a new feature branch from the master branch.
  2. Develop and commit on feature branches.
  3. After completing the development, initiate a Pull Request.
  4. Code reviewers review the code and make necessary revisions and discussions.
  5. After passing the code review, merge the code into the master branch.

Git flow strategy

The Git flow strategy is a strategy that expands on the feature branch strategy to include more branches and environments.

Strategy steps:

  1. Create a new development branch from the master branch.
  2. Develop and commit on the develop branch.
  3. After completing the development, initiate a Pull Request.
  4. Code reviewers review the code and make necessary revisions and discussions.
  5. After passing the code review, merge the code into the master branch.
  6. Create a new release branch based on the master branch, and test and deploy it.
  7. If there are bugs or issues that need fixing, create a hotfix branch from the release branch and merge it into the release branch and the master branch.

Use of Pull Requests

Pull Request is a mechanism for submitting modification requests to code warehouses, and is widely used in open source projects and team collaboration.

Initiate a Pull Request

  1. Create a new branch in the local repository.
  2. Develop and commit on the new branch.
  3. Push the branch to the remote repository.
  4. Create a Pull Request in the remote repository, specifying the target branch to merge the code into.

Code Review and Merge

  1. Code reviewers review the code in the Pull Request and provide feedback and suggestions.
  2. Committers make revisions and discussions based on feedback.
  3. After passing the code review, merge the code into the target branch.

Guess you like

Origin blog.csdn.net/huanglu0314/article/details/131177336
Git