LinuxCommandLibrary

gh-browse

Open a GitHub repository in the browser

TLDR

Open the homepage of the current repository in the default web browser

$ gh browse
copy

Open the homepage of a specific repository in the default web browser
$ gh browse [owner]/[repository]
copy

Open the settings page of the current repository in the default web browser
$ gh browse [[-s|--settings]]
copy

Open the wiki of the current repository in the default web browser
$ gh browse [[-w|--wiki]]
copy

Open a specific issue or pull request in the web browser
$ gh browse [issue_number|pull_request_number]
copy

Open a specific branch in the web browser
$ gh browse [[-b|--branch]] [branch_name]
copy

Open a specific file or directory of the current repository in the web browser
$ gh browse [path/to/file_or_directory]
copy

Print the destination URL without open the web browser
$ gh browse [[-n|--no-browser]]
copy

SYNOPSIS

gh browse [<url-or-path>] [-b,--branch <branch>] [-c,--commit <commit>] [-R,--repo <repo>]

PARAMETERS

-b, --branch <branch>
    Branch or tag to browse instead of default.

-c, --commit <commit>
    Commit hash or ref to browse.

-R, --repo [<repo>]
    Select repository (defaults to current git remote).

DESCRIPTION

The gh browse command from GitHub CLI quickly launches the web interface for a repository, file, branch, commit, issue, pull request, or release in your default browser.

In a Git repository, running gh browse without arguments opens the repository's main page on GitHub.com using the primary remote (origin). It smartly detects context: file paths open specific files; numeric arguments attempt to open matching issues or PRs; branch names switch views. Specify remote repos with --repo.

Ideal for developers switching between CLI and web UI without typing URLs. Requires GitHub authentication via gh auth login and git remotes configured. On Linux, relies on xdg-open for browser launching.

CAVEATS

Needs gh auth login; fails without GitHub access or git repo context. Uses system browser opener (xdg-open on Linux); may prompt if multiple browsers.

CONTEXT DETECTION

gh browse auto-detects:
• No args: repo overview.
• <file>: file view.
• <#>: issue/PR/release.
• URL: direct open.

EXAMPLES

gh browse
gh browse README.md
gh browse 42
gh browse --repo cli/cli --branch v2.0.0

HISTORY

Part of GitHub CLI since v0.5.0 (Jan 2020). Evolved from hub tool; actively developed by GitHub for cross-platform use.

SEE ALSO

gh(1), git(1), xdg-open(1), hub(1)

Copied to clipboard