Notes
TL;DR
With GitHub CLI, you can open the URL of the current GitHub repository with this command:
Open a GitHub repository URL from the terminal
When working in the terminal, there are times when you want to open a GitHub URL immediately.
In that case, if the repository is on GitHub, you can use the gh command (GitHub CLI) to open the URL directly in your browser.
This works as long as a remote repository is configured. If you use GitHub as the remote repository, you have probably either run the following command when creating the repository,
or you created the repository on GitHub first and then cloned it locally, so it should already be set up. You can check whether a remote repository is configured with this command:
Why I wrote this article
I remembered that I could open a GitHub repository with the gh command, but I forgot which subcommand it was.
So I searched with some likely keywords, but the simplest solution did not show up at the top.
Other methods besides gh browse that show up include:
- a git alias
- a bash/zsh alias
hub browsefrom thehubcommandgh repo view --webusing thereposubcommand ofgh
Maybe gh repo view --web used to be the only way, but now gh browse can open not only repositories but many kinds of GitHub pages directly from the terminal.
That is why I wanted to leave this note for anyone searching for how to open GitHub from the terminal.
