helps viewing repositories on the web e.g. GitHub in your browser.

View on GitHub
gem install git-browse-remote

Just run git browse-remote on your GitHub-cloned repository. This opens URL according to what branch you are on e.g.

On master
opens project page (for example).
On some branch
opens branch page (for example).

To point your commit to someone

Sometimes you will need to include revision SHA-1 in the URL for later reference. (ex. sharing an URL of an intensively developed branch on IRC)

Use --rev option to force revision-based page.

git browse-remote --rev

will navigate you to the commit page (for example).

To browse a specific file (at specific line)

Use -- path and -L line to specify a file and a line number.

git browse-remote -L1 -- .gitignore

will navigate you to the file at line 1 (for example).

Specifying a commit

To inspect a specific branch/commit, just pass it in the arguments.

git browse-remote refactor

will navigate you to the branch page (for example).

git browse-remote HEAD~1

will navigate you to the commit page (for example).

git browse-remote [-r|--remote <remote>] [--top|--rev|--ref] [-l <n>] [<commit-or-remote>] [--] [<file-or-directory>]


-r,--remote REMOTE

Specifies remote (default: "origin"). Remote is used to decide the URL to open.


Forces "top" mode (opens project top page).


Forces "rev" mode (opens commit page).


Forces "ref" mode (opens branch/tag page, may fail if none available).


Specifies file line (only meaningful when FILE specified).


Specifies target commit (default: "HEAD"). Recognized as remote if equals to one of remotes.


Specifies a single file to view.

Determining which view to open

If none of --top, --rev, --ref is supplied,

  1. If the target (specified as the argument or "HEAD") points to a branch that is named "master", opens project top ("top" mode).
  2. If the target points to a branch or a tag, opens that ref's page ("ref" mode).
  3. Otherwise, opens the corresponding revision's page ("rev" mode).
  4. If FILE is specified, opens that file's page. URL depends on whether the mode is "ref" or "rev".

If you have GitHub-like repository browser, ex. GitHub Enterprise, at, set up by:

git browse-remote --init

Then you can open this non-github-com repository viewer. The settings are wrote to ~/.gitconfig.

For GitHub repositories, this initialization is not required.

If you want to write your own repository viewer's URL rules, these variables are available:

Repository's host (e.g. "")
Repository's path (e.g. "motemen/git-browse-remote")
Array methods are available (e.g. path[-2,-1])
The ref name (e.g. "refs/heads/master")
The ref name in short form (e.g. "master")
The commit SHA-1 (e.g. "04f7c64ba9d524cf311a673ddce5722b2441e2ea")
The commit SHA-1 in short form (e.g. "04f7c64b")
ref or commit
short_ref or short_commit
File (or directory) specified
Pathname methods are available
Line specified by "-L"

For example, URL mappings for are below by default:

[browse-remote ""]
top = https://{host}/{path}
ref = https://{host}/{path}/tree/{short_ref}
rev = https://{host}/{path}/commit/{commit}
file = "https://{host}/{path}/{ and :tree or :blob}/{short_rev}/{file}{line && \"#L%d\" % line}"
motemen <>