Skip to content
LatchkeyLatchkey home

gh label create: Create Issue Labels in CI

gh label create adds a new issue or pull request label with an optional color and description.

Repo bootstrap and triage automation create the labels they rely on; --force makes the step safe to re-run.

What it does

gh label create adds a label to the repository. You set the name, an optional hex --color, and a --description. --force updates the label if it already exists instead of failing, making the command idempotent.

Common usage

Terminal
gh label create bug --color FF0000 --description "Something is broken"
gh label create needs-review --color "#0E8A16"
gh label create release --color B60205 --force

Flags

FlagWhat it does
-c, --color <hex>Label color as a hex code (with or without #)
-d, --description <text>Label description
-f, --forceUpdate the label if it already exists
-R, --repo <owner/repo>Target a specific repository

In CI

Set GH_TOKEN and permissions: { issues: write }. Use --force in bootstrap scripts so re-running the job does not error on labels that already exist. Color accepts a bare hex like FF0000 or a quoted #-prefixed value.

Common errors in CI

"HTTP 422: Validation Failed (label already exists)" means the label is present; add --force to update instead. "Resource not accessible by integration" means the token lacks issues: write. An invalid color string also raises an HTTP 422 validation error.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

Frequently asked questions

gh label create: Create Issue Labels in CI?
Repo bootstrap and triage automation create the labels they rely on; --force makes the step safe to re-run.
What it does?
gh label create adds a label to the repository. You set the name, an optional hex --color, and a --description. --force updates the label if it already exists instead of failing, making the command idempotent.
In CI?
Set GH_TOKEN and permissions: { issues: write }. Use --force in bootstrap scripts so re-running the job does not error on labels that already exist. Color accepts a bare hex like FF0000 or a quoted #-prefixed value.
Common errors in CI?
"HTTP 422: Validation Failed (label already exists)" means the label is present; add --force to update instead. "Resource not accessible by integration" means the token lacks issues: write. An invalid color string also raises an HTTP 422 validation error.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card