---
name: github
description: Work on GitHub through its gh command - sign in, create a repository, lock down its settings and Actions, set Actions secrets, turn off GitHub Pages, change visibility. Use for code hosting or GitHub Actions work, or when another skill hands over a GitHub job.
---

# GitHub

Roles: code hosting, and running builds with GitHub Actions.

GitHub's settings change. When you can browse, check docs.github.com before a step you're unsure of. When you can't, go with what you know, say so, and check the result with the person.

## Connect

Through `gh`, GitHub's command-line tool.

1. Check: `gh auth status` says logged in.
2. If `gh` is missing, install it the way the `setup-tools` skill describes: `brew install gh` (Homebrew), cli.github.com/manual/installation (Debian, Ubuntu), or `mise use -g gh` (mise).
3. Sign in: the person runs `gh auth login`. It opens the browser and keeps the login on their machine. You run `gh` with it, and never read or print its token.

`gh` can't see whether two-factor login is on without the `user` scope; ask the person instead.

## Jobs

Each changes the repository or the account: show the command and ask first. `OWNER/NAME` is the account and repository.

**Create a repository**, cloned next to their other code. `--public` instead of `--private` if that's their choice:

```bash
gh repo create OWNER/NAME --private --disable-wiki --clone
```

**Lock down a repository**:

```bash
gh repo edit OWNER/NAME --enable-projects=false --delete-branch-on-merge
gh api -X PUT repos/OWNER/NAME/actions/permissions -F enabled=true -f allowed_actions=selected -F sha_pinning_required=true
gh api -X PUT repos/OWNER/NAME/actions/permissions/selected-actions -F github_owned_allowed=true -F verified_allowed=false
gh api -X PUT repos/OWNER/NAME/actions/permissions/workflow -f default_workflow_permissions=read -F can_approve_pull_request_reviews=false
gh api -X PUT repos/OWNER/NAME/vulnerability-alerts
```

What they do: delete a pull request's branch once merged; allow only actions made by GitHub, and only when pinned to a full commit; give workflows a read-only token unless a job asks for more; alert on vulnerable dependencies. Read each back with `gh api` on the same path.

**Protect the default branch**, public repositories only (a private one needs a paid plan for this): no force pushes, no deletion.

```bash
gh api -X POST repos/OWNER/NAME/rulesets --input - <<'JSON'
{"name": "main", "target": "branch", "enforcement": "active",
 "conditions": {"ref_name": {"include": ["~DEFAULT_BRANCH"], "exclude": []}},
 "rules": [{"type": "deletion"}, {"type": "non_fast_forward"}]}
JSON
```

**Set an Actions secret**: the person does it in a terminal of their own, never through you. On macOS, after copying the value:

```bash
pbpaste | gh secret set SECRET_NAME --repo OWNER/NAME
```

It reads the clipboard, so the value never shows on screen or in the shell history. Elsewhere: `gh secret set SECRET_NAME --repo OWNER/NAME` and paste at the prompt. Then they copy something else, so the value doesn't stay on the clipboard. Check it by name: `gh secret list --repo OWNER/NAME`.

**Turn off GitHub Pages**: `gh api -X DELETE repos/OWNER/NAME/pages`. The site it served stops answering. Check: `gh api repos/OWNER/NAME/pages` answers 404.

**Make a repository private**: `gh repo edit OWNER/NAME --visibility private --accept-visibility-change-consequences`. A repository serving GitHub Pages turns private only after Pages is off: Pages on a private repository needs a paid plan.

**Account security**, human steps: two-factor login at github.com/settings/security (a passkey is easiest), and no collaborators they don't know about (the repository > Settings > Collaborators).
