Skip to content
zhaochunqiPublic

About

Open the current Git repository in your browser — after installation, just run git open

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

Git Open

codecov

macOS · Linux · Windows · WSL — a single static binary that opens the current Git repository in your browser, with no runtime dependencies and no configuration.

Important

After installation, just run git open:

git open

Run it inside any Git repository and that repository opens in your browser — on your current branch. That's the whole workflow; git-open works too, since git treats it as the open subcommand. The supported hosts are listed under Hosts and branch URLs; hosts without a known branch URL still open the repository root, and any host can be mapped to a style in the config file.

🚀 Quick Install

The fastest way is a package manager:

mise (macOS · Linux · WSL):

mise use -g github:zhaochunqi/git-open

Nix:

nix profile install github:zhaochunqi/git-open

Homebrew (macOS):

brew install --cask zhaochunqi/tap/git-open

Prebuilt binaries are published for every supported platform as well. Pick the asset that matches your machine and follow Installation Options:

Platform Release asset
macOS (Intel / Apple Silicon) git-open_Darwin_x86_64.tar.gz / git-open_Darwin_arm64.tar.gz
Linux (x86_64 / arm64) git-open_Linux_x86_64.tar.gz / git-open_Linux_arm64.tar.gz
Windows (x86_64 / arm64) git-open_Windows_x86_64.zip / git-open_Windows_arm64.zip
WSL (WSL1 / WSL2) install the Linux binary inside your distro — see WSL

Features

  • Cross-platform by design — macOS (Intel / Apple Silicon), Linux (x86_64 / arm64) and Windows (x86_64 / arm64), plus WSL.
  • WSL aware — inside WSL the URL is handed to your Windows default browser, so no WSLg, X server or xdg-open is required.
  • Branch aware — opens the current branch, while main / master fall back to the repository root.
  • Host aware, vendor neutral — GitHub, GitLab, Bitbucket, Gitea/Forgejo/Codeberg, SourceHut and Azure DevOps are recognised by hostname. Any other host can be mapped to a named style (github, gitlab, gitea, ...) or a raw path template in the config file, and unknown hosts open the repository root instead of a guessed URL.
  • Configurable browser — ~/.config/git-open/config.yaml (browser: ...), following the XDG Base Directory spec, or the BROWSER environment variable.
  • git -C style -C flag — run as if started in another directory.
  • Lightweight — one static binary per platform and no runtime dependencies.

Hosts and branch URLs

git-open picks the branch URL from the remote's hostname, so the same command works on every supported service. These hosts are recognised out of the box — the style column is the name you use in the config file:

Host pattern Style Branch URL
github.com github /tree/<branch>
gitlab.com gitlab /-/tree/<branch>
bitbucket.org bitbucket /src/<branch>
codeberg.org, gitea.com gitea /src/branch/<branch>
git.sr.ht sourcehut /tree/<branch>
dev.azure.com, *.visualstudio.com azure-devops ?version=GB<branch>
any hostname with a gitlab label, e.g. gitlab.example.com gitlab /-/tree/<branch>
any hostname with a gitea or forgejo label gitea /src/branch/<branch>

On main / master, and on any host that is not in the table, git-open opens the repository root instead. A host is never guessed: GitHub Enterprise, Azure DevOps Server and self-hosted instances on a neutral domain such as git.example.com stay at the root until you map them to a style (or to none to keep them there) under Repository hosts.

Platform Support

Platform Status How the URL is opened
macOS supported open
Linux supported xdg-open
Windows supported cmd /c start
WSL (WSL1 / WSL2) supported xdg-open → wslview → explorer.exe → powershell.exe → cmd.exe
Others (FreeBSD, Plan 9, ...) not supported exits with unsupported platform: <goos>

WSL is detected from WSL_DISTRO_NAME / WSL_INTEROP, with the /proc/version kernel string (microsoft) as a fallback. Any platform can be overridden with the browser option — see Configuration and WSL.

Installation Options

Package managers are the easiest route; use the prebuilt binaries if you would rather install manually.

mise

For users who prefer mise for version management (works on macOS, Linux and WSL):

Install the latest release globally:

mise use -g github:zhaochunqi/git-open

Or pin a specific release:

mise use -g github:zhaochunqi/git-open@2.9.0

This uses mise's github backend, which installs pre-built binaries straight from GitHub Releases. The older ubi:zhaochunqi/git-open syntax still works but is deprecated — migrate by replacing ubi: with github: in your existing config. The equivalent mise.toml entry is:

[tools]
"github:zhaochunqi/git-open" = "latest"

Nix

Using flakes (recommended):

One-shot run without installing:

nix run github:zhaochunqi/git-open

Install into your profile:

nix profile install github:zhaochunqi/git-open

Or pin a release tag:

nix profile install github:zhaochunqi/git-open/v2.9.0

From a local checkout:

nix build
./result/bin/git-open version

Development shell with Go toolchain:

nix develop

Homebrew (macOS only)

This tap ships a cask, and Homebrew casks only work on macOS. (Homebrew itself also runs on Linux, but without cask support.) On Linux, use mise, Nix or the prebuilt binary instead.

brew install --cask zhaochunqi/tap/git-open

Prebuilt binaries (manual, all platforms)

Download the asset for your platform.

macOS (Intel):

curl -L https://github.com/zhaochunqi/git-open/releases/latest/download/git-open_Darwin_x86_64.tar.gz -o git-open.tar.gz
tar -xzf git-open.tar.gz
chmod +x git-open
sudo mv git-open /usr/local/bin/

macOS (Apple Silicon):

curl -L https://github.com/zhaochunqi/git-open/releases/latest/download/git-open_Darwin_arm64.tar.gz -o git-open.tar.gz
tar -xzf git-open.tar.gz
chmod +x git-open
sudo mv git-open /usr/local/bin/

Linux (x86_64):

curl -L https://github.com/zhaochunqi/git-open/releases/latest/download/git-open_Linux_x86_64.tar.gz -o git-open.tar.gz
tar -xzf git-open.tar.gz
chmod +x git-open
sudo mv git-open /usr/local/bin/

Linux (arm64):

curl -L https://github.com/zhaochunqi/git-open/releases/latest/download/git-open_Linux_arm64.tar.gz -o git-open.tar.gz
tar -xzf git-open.tar.gz
chmod +x git-open
sudo mv git-open /usr/local/bin/

On Windows, download the zip from the same release and add the extracted folder to your PATH:

Invoke-WebRequest -Uri https://github.com/zhaochunqi/git-open/releases/latest/download/git-open_Windows_x86_64.zip -OutFile git-open.zip
Expand-Archive -Path git-open.zip -DestinationPath "$env:LOCALAPPDATA\git-open"
# then add %LOCALAPPDATA%\git-open to your PATH

Asset names always follow git-open_<OS>_<arch>: Darwin_arm64 for Apple Silicon, Linux_arm64 for arm64 Linux, Windows_arm64 for Windows on ARM.

WSL users install the same Linux binary inside their distribution — there is no separate package. Everything else is handled automatically; see WSL for the details.

Usage

Navigate to your project's directory and run the following command:

git-open or git open

This will open your repository in the default web browser.

To print the repository name (e.g. github.com/zhaochunqi/git-open):

git-open repo

To run as if started in a different directory (e.g. from a script that isn't inside the repo):

git-open -C /path/to/repo repo

The -C flag mirrors git -C: it may be given multiple times, and a non-absolute path is relative to the previous one.

To print the URL instead of opening a browser:

git-open --plain (or -p)

WSL (Windows Subsystem for Linux)

WSL distributions normally have no X server, so xdg-open is not installed. When running under WSL, git-open tries these openers in order and uses the first one available:

Order Opener Notes
1 xdg-open used when WSLg provides it, so your Linux default browser wins
2 wslview the wslu package, optional
3 explorer.exe Windows default browser, no extra setup needed
4 powershell.exe URL passed as a PowerShell single-quoted literal
5 cmd.exe URL passed as a quoted argument to start

WSL is detected from WSL_DISTRO_NAME / WSL_INTEROP; when neither is set, the kernel string in /proc/version is checked for microsoft, which both WSL1 and WSL2 report. Everything else is ordinary Linux behaviour, so installing the Linux binary is all the setup required.

If none of the openers is available, git-open fails with a pointer to the fix: install wslu (sudo apt install wslu), enable Windows executable interop, or configure a browser explicitly (see Configuration):

browser: wslview

A full Windows path works too, which is useful when you want a browser other than the Windows default one:

browser: /mnt/c/Program Files/Google/Chrome/Application/chrome.exe

Configuration

git-open reads the first file that exists, in this order (following the XDG Base Directory specification):

  1. the path given to --config — always wins when passed
  2. $XDG_CONFIG_HOME/git-open/config.yaml — i.e. ~/.config/git-open/config.yaml when XDG_CONFIG_HOME is not set
  3. ~/.git-open.yaml — the legacy location, still supported
# Command used to open the URL, executed with the URL as its only argument.
browser: explorer.exe

The BROWSER environment variable is honoured as well, so a one-off override needs no config file:

BROWSER=wslview git open

When browser is set it takes precedence over the platform defaults listed in Platform Support, which makes it the escape hatch for any platform-specific behaviour.

Repository hosts

Branch links are chosen by the remote's hostname. The recognised hosts and the style each one maps to are listed under Hosts and branch URLs. To support a host that is not recognised — GitHub Enterprise, Azure DevOps Server, or a self-hosted instance on a neutral domain such as git.example.com — map its exact hostname (not the whole remote URL) to a style:

hosts:
  git.internal.example: gitea
  gitlab.internal.example:
    style: gitlab
  legacy.example.com: none          # repository root only

A raw template works too — any value containing {branch} is used verbatim — and the nested object also accepts a branch key, which wins over style:

hosts:
  custom.example.com: "/-/tree/{branch}"
  other.example.com:
    branch: "/src/branch/{branch}"

If most of your instances run the same software, set default_style once. It applies only to hosts with no built-in rule and no override, so the services in the table keep their own path:

default_style: gitea

A misspelled style is an error rather than being silently ignored: git open fails with a message listing the known styles. --version and help still work, so a broken config never locks you out of the CLI.

Testing

This project follows Go testing best practices. Here's how to run the tests:

Running Tests

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run benchmark tests
go test -bench=. ./...

Test Structure

The tests are organized as follows:

  • Unit tests for core functionality
  • Integration tests for git repository operations
  • Benchmark tests for performance-critical functions

The test suite uses a custom test utility package (internal/testhelper) that provides common testing functions and fixtures.

Test Coverage

We aim to maintain high test coverage with:

  • Multiple test cases for each function
  • Edge case testing
  • Error condition testing
  • Performance benchmarking for critical paths

Contributing Tests

When adding new features, please ensure:

  1. Add corresponding test cases
  2. Include both positive and negative test scenarios
  3. Add benchmark tests for performance-sensitive functions
  4. Use the provided test utilities from internal/testhelper

Contributing

Contributions are welcome! If you have any suggestions, improvements, or bug fixes, please submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

About

Open the current Git repository in your browser — after installation, just run git open

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages