Open GitHub Repository Pages Precisely with gh browse
You will use gh browse to open the current GitHub repository, a file or directory, an issue, a pull request, a commit, or a repository administration page. You can first print the destination URL instead of launching a browser, which makes the command easier to check and script. Allow about ten minutes for a first run. You need GitHub CLI installed, a local Git repository with a usable remote, and network access to GitHub. No command in this guide needs sudo.
The route
Jump straight to the step you need, or tick off Done means at the end.
1. Check the installed command
Start by checking which executable will run and which version it provides:
$ command -v gh
/usr/bin/gh
$ gh --version
gh version 2.87.3 (2026-02-23)
$ gh browse --help
This guide was checked with GitHub CLI 2.87.3. The installed command includes options such as --actions and --blame that are not present in the local March 2026 gh-browse(1) manpage. Run the help command on the machine where a script will run, and do not assume that every older package exposes those newer options.
Checkpoint
If command -v gh prints nothing, stop here and install GitHub CLI through your normal package-management process. Do not work around a missing executable by copying a binary into a repository.
2. Confirm the repository remote
With the shell inside the repository you want to visit, inspect its remotes:
$ git remote -v
origin [email protected]:OWNER/REPOSITORY.git (fetch)
origin [email protected]:OWNER/REPOSITORY.git (push)
The remote must identify a GitHub repository that your account can resolve. The current branch does not need to be pushed for gh browse to open the repository, but the repository still needs a usable GitHub remote. If there are several remotes, inspect them before choosing one. The command normally derives the repository from the Git checkout, not from a directory name.
If there is no remote, gh browse --no-browser fails with an error such as unable to determine base repository: no git remotes found. That is a repository configuration problem. Add or correct the remote only if you have deliberately decided where this checkout belongs; changing a remote affects later Git operations and is not part of opening a page.
3. Preview the repository URL
Use --no-browser to print the URL. This is the safest first invocation because it does not open a browser and does not change the repository or the remote:
$ gh browse --no-browser
https://github.com/OWNER/REPOSITORY
Review the host, owner and repository before opening the address. The ordinary form opens that repository home page in the default browser:
$ gh browse
On a graphical desktop this hands the URL to the system browser. In a remote shell, use --no-browser and copy the printed address to a browser you control. You can select another browser with the BROWSER environment variable, as documented by the installed command.
4. Open a file, directory, issue or pull request
Pass one positional argument for the page you need. A repository-relative path selects a file or directory:
$ gh browse --no-browser scripts/
https://github.com/OWNER/REPOSITORY/tree/main/scripts
$ gh browse --no-browser README.md
https://github.com/OWNER/REPOSITORY/blob/main/README.md
The branch in the URL depends on the repository's default branch. To select a line in a file, append a colon and line number:
$ gh browse --no-browser README.md:42
https://github.com/OWNER/REPOSITORY/blob/main/README.md#L42
A number selects an issue or pull request:
$ gh browse --no-browser 217
https://github.com/OWNER/REPOSITORY/issues/217
GitHub uses the same number space for issues and pull requests. Check the resulting page before sharing it, especially when a number could refer to either kind of item.
5. Pin content to a branch or commit
Use --branch when you want a named branch rather than the default branch:
$ gh browse --no-browser README.md --branch bug-fix
https://github.com/OWNER/REPOSITORY/blob/bug-fix/README.md
Use --commit for a stable revision. Prefer a full, reviewed SHA when a URL will be kept in documentation:
$ gh browse --no-browser README.md --commit=77507cd94ccafcf568f8560cfecde965fcfa63
https://github.com/OWNER/REPOSITORY/blob/77507cd94ccafcf568f8560cfecde965fcfa63/README.md
The local manual describes the default commit as the last commit. The installed command also accepts the value last; leaving the option out is clearer when you simply want the branch's current content. A branch can move after you create its URL, while a commit SHA identifies the same revision unless that commit becomes inaccessible.
6. Choose repository sections and another repository
Use the section flags when the page is known by its repository area:
$ gh browse --no-browser --releases
https://github.com/OWNER/REPOSITORY/releases
$ gh browse --no-browser --projects
https://github.com/OWNER/REPOSITORY/projects
$ gh browse --no-browser --wiki
https://github.com/OWNER/REPOSITORY/wiki
$ gh browse --no-browser --settings
https://github.com/OWNER/REPOSITORY/settings
The installed 2.87.3 command also has --actions for repository actions. The current upstream manual documents --blame for a file blame view, including a line-number example. Treat both as version-sensitive: verify them with gh browse --help before putting them in a shared script.
To browse a different repository without changing the current checkout, use --repo:
$ gh browse --no-browser --repo OWNER/REPOSITORY --releases
https://github.com/OWNER/REPOSITORY/releases
For GitHub Enterprise, include the host in the documented form HOST/OWNER/REPO. A misspelled repository can produce a URL that GitHub reports as not found, or a GraphQL resolution error. Check the printed destination and repository spelling before troubleshooting authentication.
7. Handle failures without making unrelated changes
If the command cannot determine the base repository, inspect git remote -v from the directory where you ran it. If a file or branch URL is wrong, use --no-browser again with an explicit --branch or --commit. If GitHub says the repository does not exist, verify the host, owner, repository name and your access in a normal browser. Do not expose a personal access token in a command line, URL, shell history or article example.
There is no undo operation for a normal gh browse invocation: it only opens or prints a URL. The repository, working tree, Git remote and GitHub data remain unchanged. The exception is the destination page itself. If you use the browser to change settings, projects or other repository data, follow that page's review and recovery controls separately. Preview the URL first when a flag could take you to an administrative area.
Done means
gh --versionandgh browse --helpwere checked on the machine that will run the command.- The checkout's remote points to the intended GitHub repository.
gh browse --no-browserprinted a destination you reviewed.- Files, lines, issues, pull requests and repository sections were selected with the correct positional argument or flag.
- A branch or full commit SHA was used when a link needed a deliberate revision.
- No remote, working-tree or repository setting was changed by the command.