Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Last active September 12, 2025 09:24
Show Gist options
  • Select an option

  • Save igrigorik/6666860 to your computer and use it in GitHub Desktop.

Select an option

Save igrigorik/6666860 to your computer and use it in GitHub Desktop.
Open GitHub URL for current directory/repo...
alias gh="open \`git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\`"
@paulmicheli

paulmicheli commented Sep 2, 2020

Copy link
Copy Markdown

Just and FYI for Linux users

"open" is native on OS X, on linux you can just define it as alias open=xdg-open,

#Open GitHub from Repo
alias gh="xdg-open \`git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\`"

@davetownsend

Copy link
Copy Markdown

this is a nice tool for doing this kinda stuff https://github.com/paulirish/git-open

@ricardoribas

Copy link
Copy Markdown

@JustinTRoss

JustinTRoss commented Dec 30, 2020

Copy link
Copy Markdown

The alias commands above using print need the argument escaped. awk '{print $2}' should be awk '{print \$2}'.

Full command here:

alias gh="open \`git remote -v | grep fetch | awk '{print \$2}' | sed 's/git@/http:\/\//' | sed 's/com:/com\//'\`| head -n1"

@kuncevic

kuncevic commented Sep 2, 2021

Copy link
Copy Markdown

This one works great for me https://github.com/paulirish/git-open

@eytanhanig

eytanhanig commented Sep 30, 2021

Copy link
Copy Markdown

I recently updated mine to work regardless of whether you are in the current repo. It supports both relative and absolute paths:

#!/bin/sh

##  Open file or directory in web browser
##  Syntax: git-web $path [$branch]
path=${1:-"."}

if [ -d ${path} ]; then
  file_name=""
  cd ${path}
else
  file_name=$(basename ${path})
  cd $(dirname ${path})
fi
project_url=$(git config remote.origin.url | sed "s~:~/~" | sed "s~git@~https://~" | sed "s~\.git~~")
branch=${2:-$(git symbolic-ref --quiet --short HEAD)}
git_directory=$(git rev-parse --show-prefix)
echo ${project_url}/tree/${branch}/${git_directory}${file_name}
open ${project_url}/tree/${branch}/${git_directory}${file_name}

@kartikeytewari

Copy link
Copy Markdown

With the new gh cli tool just use: gh repo view --web

@nickangtc

Copy link
Copy Markdown

If using VS Code, one could also install the GitLens extension (good for other things too) and use the command palette (cmd + shift + P) > GitLens: Open Repository on Remote

@yohanb

yohanb commented Jun 2, 2022

Copy link
Copy Markdown

With the new gh cli tool just use: gh repo view --web

even easier, gh browse

@joeflack4

joeflack4 commented Jun 4, 2022

Copy link
Copy Markdown

@drewbo worked for me on mac, thanks

Edit: Well, I don't actually want to use this, because when I source my .bash_profile now, I get this as a result:

fatal: not a git repository (or any of the parent directories): .git

@mathieux51

Copy link
Copy Markdown

With Github CLI, this is exactly what I was looking:

gh browse .

Thanks @yohanb 🙏

@giovannipcarvalho

Copy link
Copy Markdown

Quick and dirty if you already have the vim plugin rhubarb installed:

vim +GBrowse +q

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment