LinuxCommandLibrary

gh-repo

Manage GitHub repositories from the command line

TLDR

Create a new repository interactively

$ gh repo [[new|create]]
copy

Clone a repository
$ gh repo clone [owner]/[repository]
copy

Fork and clone a repository
$ gh repo fork [owner]/[repository] --clone
copy

View a repository in the default web browser
$ gh repo view [repository] [[-w|--web]]
copy

List repositories owned by a specific user or organization (if the owner is not set, the default owner will be the currently logged in user)
$ gh repo [[ls|list]] [owner]
copy

List only non-forks repositories and limit the number of repositories to list (default: 30)
$ gh repo [[ls|list]] [owner] --source [[-L|--limit]] [limit]
copy

List repositories with a specific primary coding language
$ gh repo [[ls|list]] [owner] [[-l|--language]] [language_name]
copy

SYNOPSIS

gh repo <subcommand> [<args>...] [-R OWNER/REPO]

PARAMETERS

-R, --repo [HOST/]OWNER/REPO
    Select another repository using the [HOST/]OWNER/REPO format or exit if not found

-h, --help
    Help for repo

DESCRIPTION

gh repo is a core command in the GitHub CLI (gh) toolset, enabling seamless management of GitHub repositories directly from the Linux terminal. It supports essential operations like creating new repos, cloning existing ones, forking projects, listing owned or collaborated repositories, syncing forks, viewing repo details, and even deleting repositories.

Designed for developers, it integrates with Git workflows, authenticates via GitHub tokens or SSH, and respects repository permissions. For instance, gh repo create prompts for repo name, description, and options like public/private or adding README, while gh repo clone simplifies fetching any accessible repo without manual URL copying. It leverages GitHub API under the hood, providing JSON output options for scripting.

Ideal for CI/CD pipelines, team collaborations, or personal projects, it reduces context-switching between browser and terminal. Requires gh auth login for full functionality and works across GitHub.com, Enterprise, and organizations.

CAVEATS

Requires GitHub CLI installed and authenticated via gh auth login. Some actions need write permissions. Rate-limited by GitHub API. Not for local Git ops—use git for that.

SUBCOMMANDS

clone: Clone repo
create: Create new repo
delete: Delete repo
fork: Fork repo
list: List repos
sync: Sync fork
view: View repo details

EXAMPLES

gh repo create my-project — Interactive new repo
gh repo clone OWNER/repo — Clone by name
gh repo view --web — Open in browser

HISTORY

Introduced in GitHub CLI beta 0.5.0 (Feb 2020). Stabilized in v1.0 (Aug 2021), with major enhancements in v2.0+ (2022+), adding sync, better org support, and API extensibility.

SEE ALSO

gh(1), git-clone(1), git(1), hub(1)

Copied to clipboard