Git branch management has been implemented in both online and local merges. After all: talk is a sham. But only practice does not arrange, can only be a silly handle. How does branch management work?

Let’s start with a classic graph from GitLab as a general overview, which is also convenient to understand branch management and direction:

Scene preset

Consider the company’s development project called Hogwarts_Online2, which includes the live branch master, development branch Develop, test branch Release, and personal development feature branch

Feature branches and Develop branches

Create your own branch locally and pull files from the Develop branch:

1.2) Create a new file gitflowdemo. TXT in the current branch and enter “study git”; Then add and commit

1.3) Use git pull to check whether the remote develop branch conflicts with the current branch:

Note: Pull the remote code before push, in case the remote code is updated by someone else during development. If there are code conflicts, two people negotiate conflict resolution. In multiplayer development, conflict is inevitable.

Git push origin gitflowDemo:

Merge Request on GitLab and merge on develop branch:

If you want to abort this merge, use 'git merge --abort'

create merge request:

Select the Develop branch:

Merge without conflicts:

Finally we can see the successful merge into the Develop branch:

We can also see where the branches go in the graph:

This completes the pull and merge of code for the properties and Develop branches

Alternatively, the develop branch at work may be open to push, so you can modify the merge locally and push it to remote Develop

Change the gitflowdemo. TXT file to

add,commit,push

Switch to the local Develop branch, pull the latest code, merge the local gitflowDemo branch, and push into the remote Develop branch

Check for updates on GitLab:

The release branch

The Develop branch changes frequently, and the Master branch is an upper bound, so you need a beta version of the branch, which is the Release branch

The specific commit operations are the same as those described in 1 Develop.

hotfixes

Sometimes a very urgent bug occurs and needs to be modified immediately. It is too late to merge tests on all branches. Create a bugfix branch using hotfixes to bypass other branches and merge it into the master.

Note: This kind of untested online situation is very dangerous, I have seen; When I was working in Huawei, one of my team development colleagues modified one or two lines of code. Thinking there would be no problem, he skipped our test and released the code directly through others. At that time, I was in GNSS group. As a result, the positioning function of more than 10 million mobile phones is at risk of failure, which has caused a lot of complaints and a great impact. In the end, the relevant developers had to stop their vacation, and our test team worked overtime for seven days in November. We paid a lot for this small change

3.1) Create bugfix branch and modify file push to remote branch:

3.2) If you check GitLab at this time, you will find an additional branch of bug02 that has been pulled from the master branch:

3.3) The final master permission owner does the merge.

3.4) After the bug is fixed on the master branch, it is possible that the changes on the Master branch are already ahead of other branches; At this point, you need to update the other branches and merge the master branch; At the same time, remove the Bugfix branch to keep it as clean as possible.

supplement

4, add

git log

rebase

Change the base, merge branches can change the base line of the branch direction, when there are many branches, can simplify the display of branches, merge branches to make the process look concise

Comparison with branch direction after merge:

In addition, rebase can modify the history of the commit (not commonly used and not recommended)

Note: Use of rebase rules 1, do not perform rebase 2 on public branches, primary branches for protection

git diff

Common diff tools:

  • Diff — show only the increase (+) or decrease (-) of a row
  • Vimdiff — More direct than diff seems
  • IDE – powerful tools, clear presentation, easy to use


(Article from Hogwarts Testing Institute)

Welfare benefits:

Front-line Internet famous enterprises test development position internal promotion channel

Test development internal communication circle, expand your test network

For free: Interface testing + Performance testing + Automated testing + Test development + Test cases + resume template + test documentation