如何获取GitHub组织的仓库默认配置?获取及更新组织默认标签、默认分支的API是否存在?
Great question—let's break this down step by step, since I’ve faced similar API gaps while building GitHub Apps for organizational workflows.
1. 组织级默认标签:当前API限制与替代方案
Unfortunately, GitHub doesn’t currently offer a dedicated REST or GraphQL API endpoint to fetch or set organization-wide default tags. Tags remain a repository-level resource, meaning every repo manages its own tag set independently.
That said, you can work around this with a couple of practical approaches:
- Use a template repository (like the
.githubrepo many organizations use for community health files) as your source of truth for default tags. Define all your organization’s standard tags here, then have your App fetch this repo’s tag list via the repository tags API, and sync those tags to every other repo in the organization. - Maintain a centralized list of default tags (stored in something like GitHub Secrets for your organization, or a dedicated config repo). Your App can pull this list on each run, then check each target repo—creating any missing tags automatically.
2. 组织默认分支:可用API端点
Good news here—GitHub does have APIs to manage the default branch name that applies to new repositories in your organization:
- Fetch the current default branch setting
This request returns your organization’s repository default config, including theGET /orgs/{org}/settings/repository-defaultsdefault_branch_namefield which holds your organization’s default branch name. - Update the default branch setting
Send a JSON body with the new default branch name, like:PATCH /orgs/{org}/settings/repository-defaults{"default_branch_name": "main"}
3. 获取组织仓库默认配置
The same GET /orgs/{org}/settings/repository-defaults endpoint mentioned above is how you retrieve your organization’s full set of repository default settings. It returns a range of defaults that apply when creating new repos, including:
- Default branch name
- Whether private repositories are allowed by default
- Default state for Issues, Projects, and Wiki features
- Default open source license template
- Whether head branches are automatically deleted after merging
- Other repo-creation default behaviors
内容的提问来源于stack exchange,提问作者Sayak Mukhopadhyay

