An overview of the

Git is a free, open source distributed version control system designed to handle everything from small to large projects quickly and efficiently. The following article summarizes the use of the branch model for Git in combination with online [1] and real-world projects

The project contract

Branch description

We usually have three resident branches on the server: Develop, Test, and Master

  • developRepresents the test environment
  • testRepresents the test environment
  • masterThis is the production environment

It can be considered that:

  • masterAny point on the branch belongs toreleaseCode that can be deployed to production servers
  • developEvery point on the branch is up and running, but the latest code is untested and may still existbug
  • testEach point on the branch represents completed development and ongoing testing, and the test system deployment service is the branch

Note: Do not commit code directly on the master branch. Do not use Git push Origin master directly

Branch name

Name (XXX can represent the id of gitlab or Github to create issues), hotfix, fix, Custom, feature and improvement can respectively represent the requirement type, as follows:

  • Xxx-hotfix: Online bug requirement
  • Xxx-fix: Bug requirements in undeployed code
  • Custom -{project name} : Customize project requirements
  • Xxx-feature: new feature requirement
  • Xxx-improvement: Improvement needs include refactoring, etc

Common commands

Git clone https://github.com/3tu/spring-cloud-demo.git # from online code cloning, git branch code # to check the local branch, Git fetch && git fetch is a new branch of the develop branch Git status # check the status of the locally modified files, or install the client software to check the status of the branch, eg:SourceTree git add. # Add the modified files to the local staging area, ". Git commit -m "change notes" # commit the staging code to the local sub-branch git push origin xxx-xxx # commit the local branch to the remote repositoryCopy the code

The main process

The main process of production environment can be roughly divided into the following five types

  • Released Versions (production environment)bugTo deal with
  • Unreleased version (test environment)bugTo deal with
  • New feature development
  • Improve or refactor development
  • Project customization development

Bug handling of released versions

Check out from the test branch, and merge into test and Develop in both directions once processing is complete. The checked out branch is not committed to the server

#testBranch detectionGit fetch && git rebase Git checkout -b XXX -hotfix # Switch out the BUG sub-branch from the test branch. XXX represents the ID value of issues 
#${xxx-hotfix}Complete Bug handling on the branch with one or more Git commits
 
#Two-way merge totestAnd developGit rebase git merge --no-ff ${XXX -hotfix} # Git merge --no-ff ${XXX -hotfix} # Git branch -d ${XXX -hotfix} git branch -d ${XXX -hotfixCopy the code

Unreleased version bug handling

#Check out from the Develop branchGit fetch && git rebase Git checkout -b xxx-fix # cuts out the BUG child branch from the Develop branch 
#${xxx-hotfix}Complete Bug handling on the branch with one or more Git commits
 
#Merge into the Develop branchGit rebase git merge --no-ff ${xxx-fix} # Develop git branch -d ${XXX -fix} #Copy the code

New feature development

Check out from the Develop branch and merge to the Develop branch, where new features checked out need to be submitted to the server to facilitate collaboration

#Check out from the Develop branchGit rebase # git rebase Git checkout -b ${XXX -feature} # merge with local changes (if any) git checkout -b ${XXX -feature} # merge with local changes 
#Submit the new feature branch to the server
git push origin ${xxx-feature}
 
#${xxx-feature}Branch development, multiple Git commit and Git push Origin${xxx-feature}
#Create a pull request in GitLab
Copy the code

Improve or refactor development

The improvement or refactoring process is the same as the new feature development process. Name the branch with ${xxx-improvement}

Custom project development

Check out custom-${name} from the master branch and merge it into the custom-${name} branch after development. The branch is submitted to the server for easy collaboration

#Check out from the master branchGit checkout master git fetch && git rebase git checkout -b custom-${name} # 
#Submit custom projects to branch to the server
git push origin custom-${name}
 
#In the custom -${name}Develop on the branch and commit to the custom branchGit add. Git commit -m "commit" git fetch && git rebase # Project custom branches do not merge to other branches#If detailed customization is required, the sub-branch code can be moved to custom (custom project Group)
Copy the code

Other processing

Merge request processing

#Code reviews
#Merge into the Develop branch
git checkout develop
git merge --no-ff ${feature_name} 
 
#Commit Develop to the server and delete the new feature branch
git push origin develop
 
#Delete a local branch
git branch -d ${feature_name}
#Delete a branch on the server
git push origin :${feature_name}
Copy the code

Git rebase is recommended instead of git merge or git pull

Clear locally resident branches

Git branch-rd origin/{branch-name} # 
#When developing new features, you need to merge the develop code into your new feature branchGit rebase ${XXX -feature} # git rebase ${XXX -feature} # git rebase # Pull the Develop branch code from the new function branch to merge 
#Merge the latest Develop branch code into the new feature branch, where conflicts may need to be handledGit push origin :${xxx-feature} # git push origin :${xxx-feature} #Copy the code

The resources

[1] nvie.com/posts/a-suc…

I am SAN Tu, thank you friends: like, favorites and comments, we will see you next time!