LinuxCommandLibrary

gh-alias

Create shortcuts for GitHub CLI commands

TLDR

List all the aliases gh is configured to use

$ gh alias [[ls|list]]
copy

Create a gh subcommand alias
$ gh alias set [pv] '[pr view]'
copy

Set a shell command as a gh subcommand
$ gh alias set [[-s|--shell]] [alias_name] [command]
copy

Delete a command shortcut
$ gh alias delete [alias_name]
copy

Display the subcommand help
$ gh alias
copy

SYNOPSIS

gh alias {list|set name [expansion]|delete name|edit} [--shell SHELL]

PARAMETERS

list
    Display all aliases for the current or specified shell

set name [expansion]
    Create or update alias; prompts for expansion if omitted

delete name
    Remove the alias by name

edit
    Open alias config file in $EDITOR or $GH_EDITOR

--shell SHELL
    Shell to target: sh, bash, zsh, fish; defaults to $SHELL

-h, --help
    Show help

DESCRIPTION

The gh alias command, part of the GitHub CLI (gh), lets users create, list, edit, and delete shortcuts for complex gh commands. This boosts productivity by replacing long command lines with short, memorable names, ideal for repetitive GitHub workflows like managing pull requests or issues.

Aliases expand when invoked as gh <alias> [args]. They are stored in shell-specific config files (e.g., ~/.bashrc, ~/.zshrc) and auto-load on shell startup.

Supports subcommands: list shows all aliases; set creates/updates with name and expansion; delete removes by name; edit opens config in $EDITOR. The --shell flag targets specific shells, defaulting to $SHELL.

Example: gh alias set po 'pr checkout' lets gh po 123 check out PR #123. Perfect for CI/CD scripts or daily use, but requires shell reload after changes.

CAVEATS

Shell-specific; appends to init files (e.g., ~/.zshrc)—restart shell or source file to apply. Limited to supported shells; expansions must be valid gh commands.

EXAMPLE

gh alias set po 'pr checkout'
Later: gh po 456 checks out PR #456.

gh alias list outputs: po → pr checkout

SHELL DETECTION

Auto-detects via $SHELL; use --shell zsh for explicit control in multi-shell setups.

HISTORY

Introduced in GitHub CLI v0.6.0 (March 2020); enhanced with edit and fish support in v2.0+ (2022).

SEE ALSO

gh(1), git config(1)

Copied to clipboard