Skip to content

Commit d9a2fe5

Browse files
committed
Git usage
standards branching config conventional commits rebase controls
1 parent bc4a67c commit d9a2fe5

File tree

3 files changed

+242
-134
lines changed

3 files changed

+242
-134
lines changed

src/development/coding-naming-conventions.md

+12-15
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ order: 3
77
review:
88
last_reviewed_date: 2023-05-06
99
review_cycle: ANNUAL
10-
related:
11-
title: Related articles
12-
tag: branching
1310
---
1411
It is important to adopt a naming convention:
1512

@@ -102,15 +99,6 @@ Terms used in the naming conventions are:
10299
<ul>
103100
<li><code>hotfix</code></li>
104101
<li><code>develop</code></li>
105-
<li><code>build</code></li>
106-
<li><code>ci</code></li>
107-
<li><code>docs</code></li>
108-
<li><code>feature</code></li>
109-
<li><code>fix</code></li>
110-
<li><code>perf</code></li>
111-
<li><code>refactor</code></li>
112-
<li><code>style</code></li>
113-
<li><code>test</code></li>
114102
</ul>
115103
</td>
116104
</tr>
@@ -163,11 +151,20 @@ Gitlab and Github hosted repository names should use unabbreviated `natural` cas
163151

164152
### Git branches
165153

166-
The mainline branch should be named `main`. All branches should be `kebab-case` with this convention:
154+
All branches should be `kebab-case`, although change ID should be uppercase
167155

168-
> `{type}/{change ID}-{brief description}`
156+
* The mainline branch should be named `main`.
157+
* release candidate branches should follow the convention:
169158

170-
A single branch should be used per change/ticket.
159+
> `develop-{version}`
160+
> or
161+
> `hotfix-{version}`
162+
163+
* change candidate branches should follow the convention:
164+
165+
> `{change ID}-{brief description}`
166+
167+
Descriptions should be kept brief, not exceeding 50 characters.
171168

172169
See [Git branching guidance](../dev-git-branching-strategy/) for a more detailed explanation of Git branch naming
173170

+11-119
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
11
---
22
layout: article
33
title: "Git branching strategy"
4-
description: "Define a branching strategy to avoid confusion and reduce risk"
5-
tags: [dev, branching]
4+
description: "A branching strategy provides a structure for pushing changes through to production"
5+
tags: [git]
66
order: 8
77
status: DRAFT
88
review:
9+
title: Related
910
last_reviewed_date: 2024-09-20
1011
review_cycle: ANNUAL
1112
---
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:
3314

3415
* __Production__
3516
* __Release candidate__
@@ -45,7 +26,7 @@ The `main` branch must contain the exact same code as production. It is created
4526

4627
### Release candidate
4728

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.
4930

5031
We use these branch names for release candidates:
5132

@@ -59,93 +40,17 @@ Projects teams should adopt a naming convention to convey additional information
5940
e.g. `develop-wcag-2-2`
6041

6142
* 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.
6344

6445
### Change candidate
6546

6647
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.
6748

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:
11650

117-
## Rebasing
51+
* `{change ID}-{brief description}`
11852

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`
14954

15055
## Workflow
15156

@@ -155,7 +60,6 @@ We recommend that developers squash commits into logical commits for change cand
15560
* Imported repositories:
15661
* may have adopted the non-standard `master` branch. This should be changed to `main`
15762
* 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
15963

16064
### Release Candidate
16165

@@ -171,17 +75,5 @@ We recommend that developers squash commits into logical commits for change cand
17175

17276
* Developer creates a new change candidate branch, `feature-xyz` branch from the newly created `develop-xyz` branch
17377
* 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

Comments
 (0)