|
| 1 | +# Git conventions |
| 2 | + |
| 3 | +For consistency, we have a handful of git conventions: |
| 4 | + |
| 5 | +- We follow a [GitHub flow model](https://githubflow.github.io/) for branch management |
| 6 | +- We follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) formatting |
| 7 | +- We write [good commit messages](https://cbea.ms/git-commit/), treating them as a source of truth |
| 8 | + |
| 9 | +Many of these conventions are suggested or enforced in tooling: for local development, [set up pre-commit](/documentation/pre-commit.md). |
| 10 | + |
| 11 | +We encourage small, tightly-scoped pull requests: this makes managing reviews simpler, allowing us to iterate on documentation quickly. |
| 12 | + |
| 13 | +## Branch management |
| 14 | + |
| 15 | +We continuously deploy from the [`main`](https://github.com/nginx/documentation/tree/main) branch. |
| 16 | + |
| 17 | +To make changes, [fork the repository](https://github.com/nginx/documentation/fork) then branch from `main`, giving your branch a prefix and descriptive name. |
| 18 | + |
| 19 | +Prefixes are typically a three letter acronym for the product it affects: |
| 20 | +- `nic/`, `ngf/`, `nim`/, `waf/`, and so forth |
| 21 | +- Use `docs/` if the change is related to the repository or not product-specific |
| 22 | + |
| 23 | +A descriptive name usually concerns what the branch actually updates: |
| 24 | +- `nic/update-helm-links` Tells someone at a glance that the branch relates to NGINX Ingress Controller and links related to Helm |
| 25 | +- `patch-27` Tells someone almost nothing at a glance: it does not include a prefix or any details about a possible topic |
| 26 | + |
| 27 | +The exception to this branch naming convention is release branches for products. These are named `<product>-<release>-<version>`: |
| 28 | +- `agent-release-2.2` |
| 29 | +- `n1c-release-1.5` |
| 30 | +- `dos-release-5.1` |
| 31 | + |
| 32 | +Typically, the technical writer for a given product will ensure that branches are kept in sync with `main`, to minimize the risk of merge conflicts. |
| 33 | + |
| 34 | +If you need to rename a branch, here's the syntax: |
| 35 | + |
| 36 | +```shell |
| 37 | +git branch -m <current-branch-name> <new-branch-name> |
| 38 | +``` |
| 39 | + |
| 40 | +## Commit messages |
| 41 | + |
| 42 | +When opening a pull request on GitHub, the very first commit from a branch is automatically pulled to populate the description. |
| 43 | + |
| 44 | +This provides an opportunity to re-use a good commit message to provide context to reviewers for the changes in a branch. |
| 45 | + |
| 46 | +The first line of a git commit message becomes the subject line, with the contents after a line break becoming the body. |
| 47 | + |
| 48 | +A subject line begins with a [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) prefix, and should be written in present imperative. |
| 49 | +- _feat: Update ConfigMap reference page_ |
| 50 | +- _fix: Remove links to missing website_ |
| 51 | + |
| 52 | +Keep the subject line around 50 characters or less: imagine the reader is using `git reflog` or `git log --oneline` to review changes. |
| 53 | + |
| 54 | +The body of the git message should have its lines kept around 72 characters or less, and can be structured as follows: |
| 55 | + |
| 56 | +- What was changed and why |
| 57 | +- How the changes were implemented |
| 58 | +- What else the changes might affect, and what may change in the future |
| 59 | + |
| 60 | +This provides enough context for a reader to get a strong impression of what the commit accomplishes, which in turn makes reviewing pull requests easier |
| 61 | + |
| 62 | +An example of a full commit message following the above conventions is as follows: |
| 63 | + |
| 64 | +``` |
| 65 | +feat: Move and update process documentation |
| 66 | +
|
| 67 | +This commit moves and updates some of the process documentation for the |
| 68 | +repository. This is an iterative process, which will continue to improve |
| 69 | +as time goes on. Some of the changes include: |
| 70 | +
|
| 71 | +- Moving the closed contributions document into the documentation folder |
| 72 | +- Moving and reframing the F5/NGINX document as "Maintainers etiquette" |
| 73 | +- Moving and renaming the "Managing content with Hugo" document |
| 74 | +- Moving the style guide from the templates folder |
| 75 | +
|
| 76 | +These files will likely be updated in a subsequent PR as we clarify the |
| 77 | +contribution process and user flow of other process artefacts, such as |
| 78 | +the pull request and issue templates. |
| 79 | +
|
| 80 | +Although we do not draw attention to it, the templates folder is being |
| 81 | +retained for reference until the style guide and Hugo archetypes contain |
| 82 | +the relevant, useful information. |
| 83 | +``` |
0 commit comments