>_ ghcli.com
ghcli / Auth & Config / gh alias set

gh alias set

Turn long commands into shortcuts

gh alias set lets you define your own shorthand for any gh command. Collapse a long, flag-heavy command into a two-letter alias, pass arguments through placeholders, and even wrap arbitrary shell commands so your whole workflow lives behind gh.

Quick answer
gh alias set prs 'pr list --author @me'

Syntax

gh alias set <alias> <expansion> [flags]

Examples

Alias for your own open PRs

gh alias set prs 'pr list --author @me'

Alias with a positional argument

gh alias set co 'pr checkout $1'

Bugs alias filtering by label

gh alias set bugs 'issue list --label bug'

Wrap a full shell command

gh alias set sync '!git pull && git push'

Overwrite an existing alias

gh alias set prs 'pr list --author @me' --clobber

Options & flags

FlagWhat it does
-s, --shellInterpret the expansion as a shell command (also enabled with a leading !).
--clobberOverwrite an existing alias of the same name.

How to use gh alias set, step by step

  1. Pick a short name and the command it should expand to.
  2. Run gh alias set prs 'pr list --author @me'.
  3. Use placeholders like $1 to accept arguments.
  4. Run it: gh prs. List all aliases with gh alias list.

Common errors and fixes

X alias named "prs" already exists

Add --clobber to overwrite it, or pick a different name.

expansion does not correspond to a gh command

For non-gh commands, prefix the expansion with ! or add --shell so gh treats it as a shell command.

Related commands

Frequently asked questions

How do I create an alias in GitHub CLI?

Run gh alias set <name> '<expansion>', for example gh alias set prs 'pr list --author @me'. Then run gh prs to use it.

How do I pass arguments to a gh alias?

Use positional placeholders in the expansion: gh alias set co 'pr checkout $1' lets you run gh co 123, which expands to gh pr checkout 123.

Can a gh alias run shell commands?

Yes. Start the expansion with ! or add --shell: gh alias set sync '!git pull && git push' runs the shell command when you call gh sync.