The gh repo command manages everything about GitHub repositories.

Cloning a Repository

gh repo clone <owner/repo>
 
# Examples
gh repo clone cli/cli
gh repo clone facebook/react
gh repo clone cli/cli -- --depth=1   # Pass flags to git clone after --

This respects your configured git_protocol (HTTPS or SSH).

Viewing a Repository

# View the current repository (must be inside a git repo)
gh repo view
 
# View any repository
gh repo view cli/cli
 
# Open in the browser
gh repo view cli/cli --web
gh repo view --web       # Current repo in browser

JSON Output

gh repo view cli/cli --json name,description,stargazerCount,primaryLanguage

Creating a Repository

From Scratch (GitHub-first)

# Interactive
gh repo create
 
# Non-interactive
gh repo create my-project --public --description "My new project" --clone
gh repo create my-org/my-project --private
gh repo create my-project --public --add-readme --license mit --gitignore Go

Key flags:

  • --public, --private, --internal — visibility
  • --clone — clone locally after creating
  • --add-readme — initialize with a README
  • --license <name> — add a license file (e.g., mit, apache-2.0)
  • --gitignore <lang> — add a .gitignore template
  • --template <owner/repo> — create from a template repository

From an Existing Local Project

cd my-local-project
git init && git add . && git commit -m "Initial commit"
gh repo create my-project --source=. --public --push

The --source=. flag tells gh to use the current directory and --push pushes the initial commit.

Forking a Repository

# Fork and clone
gh repo fork cli/cli --clone
 
# Fork only (don't clone)
gh repo fork cli/cli
 
# Fork within a cloned repo (adds your fork as a remote)
cd cli
gh repo fork

Editing Repository Settings

gh repo edit
 
# Specific settings
gh repo edit --description "New description"
gh repo edit --visibility public
gh repo edit --default-branch main
gh repo edit --enable-issues=false
gh repo edit --enable-wiki=false
gh repo edit --enable-projects=false
gh repo edit --delete-branch-on-merge
gh repo edit --allow-forking
gh repo edit --add-topic cli,golang

Listing Repositories

# Your repositories
gh repo list
 
# Another user's repos
gh repo list octocat
 
# An organization's repos
gh repo list my-org
 
# Filter by visibility and language
gh repo list --language go --visibility public --limit 50
 
# JSON output
gh repo list --json name,stargazerCount --jq '.[].name'

Renaming a Repository

gh repo rename new-name
gh repo rename new-name --repo owner/old-name

Deleting a Repository

gh repo delete owner/repo --yes

Warning: This permanently deletes the repository and all its data (issues, PRs, wiki, etc.).

Syncing a Fork

# Sync the current branch with the upstream default branch
gh repo sync
 
# Sync a specific branch
gh repo sync --branch main
 
# Sync a specific fork
gh repo sync owner/fork-name --source owner/upstream-name

Archiving / Unarchiving

gh repo archive owner/repo
gh repo unarchive owner/repo

Setting the Default Repository

When working outside a git repository, you can set which repo commands apply to:

gh repo set-default owner/repo

Or use the environment variable:

export GH_REPO=owner/repo

Deploy Keys

gh repo deploy-key list
gh repo deploy-key add key.pub --title "CI Server"
gh repo deploy-key delete <key-id>
gh repo autolink list
gh repo autolink create --key-prefix "TICKET-" --url-template "https://jira.example.com/browse/TICKET-<num>"
gh repo autolink view <id>
gh repo autolink delete <id>

Browsing Gitignore and License Templates

# List available gitignore templates
gh repo gitignore list
gh repo gitignore view Go
 
# List available license templates
gh repo license list
gh repo license view mit

Exercises

  1. Clone any public repository: gh repo clone cli/cli
  2. Create a new repository: gh repo create gh-test --public --add-readme --clone
  3. View it: gh repo view gh-test --web
  4. Edit its description: gh repo edit --description "Testing GitHub CLI"
  5. Delete it when done: gh repo delete gh-test --yes