Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I open the current GitHub branch on Web using Windows command line?

I had this command working on my Mac/Linux (Terminal) with OhMyZsh, but once I moved to Windows, I wasn't sure how to update it using Cmdr/ConEmu shell.

Basically, I want an alias that is like "goweb" that will open my default browser to the current branch on GitHub. I'm fine assuming a particular repo. Maybe a later enhancement would pull that as well using, e.g., default remote or the like..

like image 927
Ambrose Little Avatar asked Feb 14 '26 09:02

Ambrose Little


1 Answers

Another approach is to use the GitHub command-line gh, specifically gh browse, introduced with Gh 1.12.0 (June 2021)

Open the GitHub repository in the web browser.

gh browse [<number> | <path>] [flags]

Example

$ gh browse main.go --branch main
# => Open main.go in the main branch

If you just want the remote URL, add the --no-browser option.

GitHub CLI 2.1.0 (oct. 2021) brings a feature to open the latest commit of a branch in gh browse

  -c, --commit                   Open the last commit

--branch supports SHAs, -n prints only a URL, and -c links t o the latest commit.

like image 119
VonC Avatar answered Feb 15 '26 22:02

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!