Git basic operation review

What did your last company use for code management? Git, SVN

How does your Git workflow work?

Do you have any restrictions or special precautions when using Git?

Instead of using Github and code cloud for project management, the company uses its own internal platform (GitLab).

Requirements: You must be very familiar with the following commands. You must not only memorize the steps, but also master the meaning of each command

  1. Git init If a project needs to be managed with Git, it needs to be initialized
  2. Git status Checks the status of the current code (red: in development, green: in staging, nothing to commit: nothing has changed in development)
  3. Git checkout -b develop
  4. Git checkout -b feature/ XXXX create a branch based on develop
  5. Git add. Place the code in staging
  6. Git commit-m puts code from staging to a local repository
  7. Git Checkout branch name switches to a branch
  8. Git merge feature/ XXXX is a branch merged into another branch
  9. Git push pushes code from a local repository to a remote repository
  10. Git pull pulls down the latest contents of the remote host and merges them directly
  11. Git Fetch pulls the latest contents of the remote repository locally, which the user checks and decides whether to merge into the working native branch
  12. Git log Displays logs
  13. Git log — Oneline
  14. Git reset –hard XXX Restore to a node where a commit was made and you need to view it using git log

Git workflow

If you don’t have a specific and effective workflow in place on your team, confusion with Git is inevitable

The confusion comes in two ways

  1. Improper branch naming (login, ABC)
  2. The branch commit process is messy (develop)

Git workflow is a specification that defines a set of branch merges and operations. Some companies may define their own Git workflow, or they may use a third-party Git workflow

GitFlow workflow

Gitflow is a set of Git operation flow, used to standardize and simplify Git operation

Note: it is based on Git, and it is not completely replaced by the Git command, but co-exists with it. You can use GitFlow or Git directly in your project

Git-flow is not intended to replace Git. Gitflow is just a combination of several Git commands and scripts to simplify the operation process

How should Gitflow be installed

Gitflow does not need to be installed, as long as you have Git installed on your computer, you can use Gitflow

Just remember the flow of the operation and execute the git-flow command with the correct parameters, and simply execute the corresponding Git commands in the correct order

Using Gitflow:

  1. Remember the flow of the operation
  2. Git-flow command and parameters

GItFlow initialization

How to use Gitflow in a project

  1. Enter git flow init at the root of your project

  2. When you type the command, an interactive setup assistant will appear. Just press Enter and use the default Settings

    Branch name for Production Releases: Ask what is the main Branch name of our project? Branch name for "Next Release" development: What is the base Branch for our project? How do you name Feature branches? How to name feature/ XXXX Bugfix Branches? bugfix/xxxx Release branches : Hotfix Branch Hotfix/XXX Version tag prefix Hotfix/XXX Version tag prefix What are the rules for version numbers, 1.1.1Copy the code

    \

Function branch

  1. Initialize the project with git Flow init

  2. Commit the local code to the local repository

    Git add. Git commit -m initializationCopy the code
  3. Create functional branches using Gitflow

    Git flow feature start XXXXCopy the code
  1. Complete a feature

    Git flow feature finish XXXXCopy the code
  1. The feature finish command will integrate our work into the main Develop branch and:

    • Git-flow also cleans up. It will remove the currently completed branch of functionality
    • Automatically switch to the Develop branch

How to fix the Develop bug

After you merge your code into Develop, a Bug occurs and you need to create a Bugfix to fix it

  1. Create the Bugfix branch

    • The name needs to be the same as when bugfix was initialized
    • The Bugfix branch based on Develop is created only if it is consistent
    Git flow bugfix start XXXCopy the code
  2. Complete the Bugfix branch

    Git flow bugfix finish XXXCopy the code
  3. After fixing the Bugfix

    • Merge the code into Develop
    • Delete the Bugfix branch

\

Release branch

When the Develop branch meets the following two conditions, it’s time to start generating a new release

  1. It includes all new features and necessary fixes
  2. It has been thoroughly tested

As long as these two conditions are met, you can create a Release branch

  1. Create a Release branch

    • Note that the Release branch is named using a version number
    Git flow release startCopy the code
  2. End the Release branch

    Git flow Release Finish versionCopy the code
  3. At the end of the process, a color box will appear and you need to do the following

    - Press CTRL + C - Enter: Q a - press enter, usually will exit the -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- if you need to write the version number - I - insert meaning, representative can edit - press CTRL + c - since the content of the input, Need to save and exit - : w qCopy the code
  1. This command does the following:

    • First, git-flow pulls the remote repository to make sure it is currently up to date.
    • The release content is then merged into the “master” branch, so that not only is the production code the latest version, but the new functionality branch is based on the latest code.
    • For identification and historical reference, the release teaser is labeled with the name of the release
    • Cleanup operation, the version branch is removed and returned to master
    • If the company’s remote warehouse is configured with automated deployment, users will be able to see our latest features

Hotfix branch

Many times, only a few hours or days later, when a release \ master version is fully tested, minor bugs may be found. In this case, Git-flow provides a specific hotfix workflow

  1. Create the Hotfix branch

    • This branch is based on the Master branch
    Git flow hotfix start XXXCopy the code
  2. End the Hotfix branch

    Git flow hotfix Finish XXXCopy the code
  3. The process is very similar to releasing a release:

    • The completed changes are merged into the Master, as well as into the Develop branch, to ensure that the error does not reappear in the next release.

    • The Hotfix program will be marked for easy reference.

    • The Hotfix branch will be removed and switched to the “Develop” branch.

Git use precautions

  1. You can’t write any code or fix any bugs in Master, Develop, and disable !!!!!! in future development

  2. Develop needs to be created based on mater, and if there is a problem with develop code, it needs to be rebuilt based on Mater

  3. All functional branches must be created based on Develop, which should contain all functional branches

  4. It is forbidden to merge branches with each other. Later development may involve test branches, pre-release live branches and so on…

  5. If the Develop code has a bug, do not modify it directly in the Develop branch and create a Bugfix branch instead

  6. The Release branch is the pre-release branch

    • It includes all new features and necessary fixes
    • It has been thoroughly tested. If both of these are true, it’s time to start generating a new release
  7. If there is a bug in the master or Release code, do not directly modify the bug in the Master or Release branch. Create a hotfix branch to modify the bug