Skip to content

fguizc/git-xopen

Repository files navigation

git-xopen

Open a git remote's web page in your browser. Smart about SSH host aliases, and interactive when a repo has multiple remotes or push URLs.

CI npm

Why

The popular paulirish/git-open works great — until your ~/.ssh/config rewrites github.com to ssh.github.com (the common port-443 workaround), at which point it happily opens https://ssh.github.com/…. Or until your repo has a fork wired up as a second push URL, where it silently picks the wrong one.

git-xopen fixes both:

  1. Smart SSH resolution. Host aliases like ssh.github.com, altssh.bitbucket.org, vs-ssh.visualstudio.com, and ssh.<provider> are mapped back to the canonical web host. Self-hosted GitLab / Gitea / Azure instances are left as-is.
  2. Multi-remote selection. When a repo has more than one remote (or a remote with multiple url / pushurl entries), git-xopen shows an interactive picker — and you can pin a default with --set-default.

Install

npm install -g git-xopen

Or run without installing:

npx git-xopen

Once installed, Git picks up git-<subcommand> executables on PATH automatically, so you invoke it as:

git xopen

Usage

git xopen [options] [remote] [branch]

Options:
  -p, --print          Print the URL instead of opening it
      --pick           Force the selection prompt (ignore saved default)
      --set-default    Save the chosen target as the per-repo default
      --clear-default  Remove the saved default for this repo
  -h, --help           Show this help
  -v, --version        Show version

Common commands:

# Open the current branch's page
git xopen

# Open a specific branch on a specific remote
git xopen origin feat/login

# Just print the URL (useful in scripts / shell pipes)
git xopen --print

# Forget the default and pick again
git xopen --pick --set-default

Supported hosts

Provider Branch URL shape
GitHub /tree/<branch>
GitLab (hosted & self-hosted) /tree/<branch>
Bitbucket Cloud /src/<branch>
Azure DevOps ?version=GB<branch>
Gitea / Codeberg /src/branch/<branch>
sourcehut /src/branch/<branch>
Unknown hosts Falls back to /tree/<branch>

How SSH aliases are resolved

git-xopen reads remote.<name>.url and remote.<name>.pushurl directly from git config, so it does not pick up url.<base>.insteadOf rewrites (which is what causes ssh.github.com to leak into web URLs in the first place).

It then normalises known SSH aliases:

As seen in your SSH config Resolved to
ssh.github.com github.com
ssh.gitlab.com gitlab.com
altssh.bitbucket.org bitbucket.org
vs-ssh.visualstudio.com dev.azure.com
ssh.dev.azure.com dev.azure.com
ssh.<anything-else> for a known provider stripped

Self-hosted hosts (gitlab.internal.corp, git.example.com, …) are preserved verbatim.

Persisting a default

The saved default is per-repo and lives in your local git config:

[xopen]
    default = origin::github.com/OWNER/REPO

Inspect or edit directly:

git config --get xopen.default
git config --unset xopen.default

Development

npm install
npm run typecheck
npm test
npm run build
node dist/index.js --help

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors