Sub topic 11
Sharing defaults across an organization
This chapter assumes you can write a pull request template, a Markdown issue template, and a config.yml file, and that you have admin access to an organization where you can create a repository. It covers the .github repository, which supplies default templates to every repository that has none of its own.
The .github repository
Copying the same templates into every repository is tedious, and the copies drift apart. GitHub solves this with a special public repository named .github, created in your organization or user account. Files in it act as defaults for every repository in that account.
A repository gets a default only when it has no file of its own for that item. Local files always win.
What goes in the repository
Use the same paths you learned earlier, placed at the root of the .github repository:
.github/
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.yml
│ │ ├── feature_request.md
│ │ └── config.yml
│ └── pull_request_template.md
└── README.mdThe outer .github is the repository name. The inner .github folder is the usual location from the earlier chapters. GitHub also accepts the default files in the repository root or in a docs folder, but a single consistent layout is easier to maintain.
The default branch must hold the files, as it does for any repository. A template on a feature branch of the .github repository has no effect on other repositories.
Create the repository
- In the organization, create a new repository named exactly
.github. - Set its visibility to public. A private
.githubrepository does not supply defaults to other repositories. - Add the template files to the default branch.
- Open a new issue in a repository with no templates of its own and confirm that the chooser shows your defaults.
Rules that surprise people
The fallback is all-or-nothing for each kind of file. If a repository has any file in its own ISSUE_TEMPLATE folder, GitHub ignores the default issue templates for that repository. It does not merge the two sets. A repository with one local template shows only that template, and none of the organization templates.
The same applies to config.yml. A local config.yml replaces the default one, so a repository that adds its own contact links must repeat any organization-wide settings it wants to keep.
Pull request templates follow the same pattern. A local pull_request_template.md replaces the default one.
| Situation | Result |
|---|---|
| Repository has no templates, `.github` repository has them | Defaults are used |
| Repository has its own issue templates | Only the local issue templates appear |
| Repository has a local PR template, no local issue templates | Local PR template, default issue templates |
| `.github` repository is private | No defaults are shared |
A shared config.yml
This file in the .github repository disables blank issues everywhere and sends questions to one place:
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://example.com/support
about: Use the support site for usage questions instead of opening an issue.Keeping defaults useful
Write defaults that suit most repositories. A bug report asking for version, operating system, and steps to reproduce works almost everywhere. A template that mentions a specific build tool does not.
Teams with special needs can override locally. Tell them in the .github repository's README.md that a local template replaces the defaults entirely, so they should copy the shared files first and then edit.
Exercise
Your organization's .github repository holds bug_report.yml and feature_request.md. The api repository adds its own ISSUE_TEMPLATE/performance.yml. Which issue templates appear when someone opens a new issue in api, and what must you change if api should also offer the bug report?
Show answer
Only performance.yml appears, because a local ISSUE_TEMPLATE folder replaces the defaults instead of merging with them. To offer the bug report, copy bug_report.yml into the api repository's .github/ISSUE_TEMPLATE/ folder.