You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Define a branching strategy to avoid confusion and reduce risk"
5
-
tags: [dev, branching]
4
+
description: "A branching strategy provides structure for pushing changes through to production"
5
+
tags: [git]
6
6
order: 8
7
7
status: DRAFT
8
8
review:
9
+
title: Related
9
10
last_reviewed_date: 2024-09-20
10
11
review_cycle: ANNUAL
11
12
---
12
-
!!! warning Standard documentation
13
-
14
-
All projects must define and publish a branching strategy in the project documentation site. See [project documentation](#project-documentation)
15
-
16
-
!!!
17
-
18
-
A Git branching strategy is a set of rules to manage and organize code changes in a Git system. A strategy helps to:
19
-
20
-
* Prevent conflicts: Avoid merge conflicts that can occur when multiple developers work on the same project at the same time
21
-
* Increase productivity: Allow multiple developers to work on different features simultaneously
22
-
* Reduce versioning management time: Help teams to manage release of code more efficiently
23
-
24
-
There are [many Git branching strategies](https://graphite.dev/guides/git-branching-strategies) including:
25
-
26
-
* Git Flow
27
-
* Github Flow
28
-
* Trunk Based Development
29
-
30
-
## NHSBSA branching strategy
31
-
32
-
Our standard branching strategy is based off traditional Git Flow. It defines three types of branch:
13
+
Our standard branching strategy is based on traditional Git-flow and defines three types of branch:
33
14
34
15
*__Production__
35
16
*__Release candidate__
@@ -45,7 +26,7 @@ The `main` branch must contain the exact same code as production. It is created
45
26
46
27
### Release candidate
47
28
48
-
A release candidate branch will hold code intended for release into production. Quality controls such as automated acceptance tests must succeed before a release candidate is accepted for release into production.
29
+
A release candidate branch will hold code intended for release into production. Quality controls such as automated acceptance tests must succeed before a release candidate is accepted into production.
49
30
50
31
We use these branch names for release candidates:
51
32
@@ -59,93 +40,17 @@ Projects teams should adopt a naming convention to convey additional information
59
40
e.g. `develop-wcag-2-2`
60
41
61
42
* Changes must not be pushed directly to release candidate branches. Use branch protection to prevent developers from pushing.
62
-
* Rebased code may be force pushed by Maintainers only when aligning divergent production code (see [rebasing](#rebasing) below). Rebasing a protected branch will require temporary rule changes.
43
+
* Rebased code may be force pushed by Maintainers only when aligning divergent production code (see [rebasing](../dev-git/#rebasing)). Rebasing a protected branch will require temporary change of push rules.
63
44
64
45
### Change candidate
65
46
66
47
A change candidate branch is the most common type of branch, used by developers to iterate their change, before [review](../coding-peer-review/) and merge into a release candidate branch.
67
48
68
-
We adopt this convention for change candidate branch names:
69
-
70
-
*`build`
71
-
Changes that affect the build system or external dependencies (example scopes: maven, npm).
72
-
*`ci`
73
-
Changes to our CI configuration files and scripts (example scopes: Gitlab-CI, Azure Devops)
74
-
*`docs`
75
-
Documentation only changes
76
-
*`feature`
77
-
A new feature
78
-
*`fix`
79
-
A bug fix
80
-
*`perf`
81
-
A code change that improves performance
82
-
*`refactor`
83
-
A code change that neither fixes a bug nor adds a feature
84
-
*`style`
85
-
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
86
-
*`test`
87
-
Adding missing tests or correcting existing tests
88
-
89
-
Branch names must follow our [naming conventions](../coding-naming-conventions/) to include change ID and description. e.g. `feature/LIS-1234-add-back-button`
90
-
91
-
## Controls
92
-
93
-
Git repository hosting providers provide various features to add additional controls on what can be done. These must be configured to protect the branch and release process.
94
-
95
-
* Prevent unauthorised push to production and release branches
96
-
* Prevent unapproved merge of code into the release process
97
-
* Prevent non-compliant commits and branch names
98
-
99
-
::: details Gitlab configuration
100
-
101
-
* Under `Settings` > `Repository` > `Protected branches`:
102
-
* Protect named `main` branch, and wildcard `develop*` and `hotfix*`
103
-
* Allowed to merge: `Developers` and `Maintainers`
104
-
* Allowed to push and merge: `No-one`
105
-
* Allowed to force push: `No`
106
-
* Under `Settings` > `Repository` > `Branch rules`:
107
-
* Add rule for `All protected branches`
108
-
* Add approval rule
109
-
* Required approvals at `1` as a minimum. Projects may choose more approvers.
110
-
* Under `Settings` > `Merge requests`
111
-
* Merge method: `Fast-forward merge`
112
-
* Under `Settings` > `Push rules` > `Branch name`
113
-
* Branch name regex: `(main|develop|hotfix)|(build|ci|docs|feature|fix|perf|refactor|style|test)[\-\/]([A-Z]{3,4}|NO-JIRA)`
114
-
115
-
:::
49
+
Change candidate branch names follow our [naming conventions](../coding-naming-conventions/) to include change ID and description:
116
50
117
-
## Rebasing
51
+
*`{change ID}-{brief description}`
118
52
119
-
Rebasing is a way to tidy up the Git commit history. It involves rewriting commits in various ways:
120
-
121
-
* Fixing merge conflicts: Rebasing can alter changes in a branch to avoid conflict with changes in another branch.
122
-
* Cleaning up project history: Rebasing can create a cleaner project history by combining multiple commits into one.
123
-
* Editing commit messages: Rebasing can be used to edit previous commit messages.
124
-
* Deleting or reverting commits: Rebasing can be used to delete or revert commits that are no longer necessary
125
-
126
-
!!! warning Proceed with caution
127
-
Rebasing will change the Git commit graph and has potential to create an inconsistent repository that is difficult to recover from. Rebase with caution and consult your professional lead if you are unsure of what you are doing.
128
-
129
-
Whenever a shared branch is rebased, the entire team needs to be notified. Every team member will need to reset their local branch to the rewritten remote:
130
-
131
-
e.g.
132
-
133
-
```bash
134
-
git fetch --all
135
-
git reset --hard <branch> origin/<branch>
136
-
```
137
-
138
-
!!!
139
-
140
-
### Rebase or merge
141
-
142
-
We recommend that project teams rebase their branches against the upstream branch whenever they diverge. This provides a more streamlined and understandable git history, and simplifies squashing.
143
-
144
-
Merging from an upstream branch on the other hand makes squashing and reverting change more difficult.
145
-
146
-
### Squashing
147
-
148
-
We recommend that developers squash commits into logical commits for change candidate branches prior to merge into a release candidate branch. This removes unneccesary commits that can confuse and provides a clean and logical git history.
53
+
e.g. `LIS-1234-add-back-button`
149
54
150
55
## Workflow
151
56
@@ -155,7 +60,6 @@ We recommend that developers squash commits into logical commits for change cand
155
60
* Imported repositories:
156
61
* may have adopted the non-standard `master` branch. This should be changed to `main`
157
62
* must import into an empty repository in the Git hosting provider. Merging a repository into a pre-existing `main` will cause confusion in the git history
158
-
*[Controls](#controls) must be applied as above
159
63
160
64
### Release Candidate
161
65
@@ -171,17 +75,5 @@ We recommend that developers squash commits into logical commits for change cand
171
75
172
76
* Developer creates a new change candidate branch, `feature-xyz` branch from the newly created `develop-xyz` branch
173
77
* When the feature changes are complete they raise a merge request for [review](../coding-peer-review/)
174
-
* The changes are merged (ideally [commits squashed](#squashing)) in to the `develop` branch. The change candidate branch should be deleted
175
-
* The _change_ -> _release_ cycle is repeated until all the changes relating the release are stable and tested
176
-
177
-
## Project documentation
178
-
179
-
All projects must document their git branching and release strategy. Deviation from standards must also be documented along with decision records explaining the reason for deviation.
180
-
181
-
Documentation should define:
182
-
183
-
* Root git branching strategy. e.g. nhsbsa, git-flow, github-flow, trunk-based-development, other
184
-
* Branch naming convention
185
-
* Rebasing approach including rebase vs merge commits, and squashing
186
-
* Branch protection
187
-
* Approval rules
78
+
* The changes are merged (ideally [commits squashed](../dev-git/#squashing)) in to the `develop` branch. The change candidate branch should be deleted
79
+
* The _change_ -> _release_ cycle is repeated until all the changes relating to the release are stable and tested
0 commit comments