Release v1.0.2 (What’s new?).

Documentation Status https://github.com/MacHu-GWU/git_web_url-project/actions/workflows/main.yml/badge.svg https://codecov.io/gh/MacHu-GWU/git_web_url-project/branch/main/graph/badge.svg https://img.shields.io/pypi/v/git-web-url.svg https://img.shields.io/pypi/l/git-web-url.svg https://img.shields.io/pypi/pyversions/git-web-url.svg https://img.shields.io/badge/✍️_Release_History!--None.svg?style=social&logo=github https://img.shields.io/badge/⭐_Star_me_on_GitHub!--None.svg?style=social&logo=github
https://img.shields.io/badge/Link-API-blue.svg https://img.shields.io/badge/Link-Install-blue.svg https://img.shields.io/badge/Link-GitHub-blue.svg https://img.shields.io/badge/Link-Submit_Issue-blue.svg https://img.shields.io/badge/Link-Request_Feature-blue.svg https://img.shields.io/badge/Link-Download-blue.svg

Welcome to git_web_url Documentation

https://git-web-url.readthedocs.io/en/latest/_static/git_web_url-logo.png

git_web_url is a CLI tool and also a Python library that prints the URL of a local file in a git repo so you can one-click to open it in web browser.

Currently it supports:

Git Hosting Services:

  • GitHub

  • GitHub Enterprise

  • GitLab

  • GitLab Enterprise

  • BitBucket

  • BitBucket Enterprise

  • AWS CodeCommit

Git Clone Protocols:

Claude Code Skill

A ready-to-use Claude Code skill is bundled at .claude/skills/git-web-url/. Copy it into your own project’s .claude/skills/ directory and Claude will automatically know how to invoke gwu (or via uvx) when you ask it to get the web URL of a file in your repo.

CLI Usage

Note

Breaking Change in 1.0.1: The CLI now uses subcommands. The previous gwu command is now gwu url. For example, gwu /path/to/file becomes gwu url /path/to/file.

General Syntax

gwu <subcommand> [options]

Available Subcommands

  • url: Print the web URL for a file or folder in the git repository.

  • relpath: Print the relative path from the git repository root.

The url Subcommand

Print the web URL you can one-click to open in a web browser.

Basic Usage

cd into your git repo directory, or any folder inside, then run gwu url (or gitweburl url). It prints the URL for the current branch and current directory:

$ gwu url
https://github.com/your_account/your_repo/tree/your_branch/path/to/current_directory

Specify a File or Folder

Provide the absolute path of the file or folder in your local git repo:

$ gwu url /path/to/your_repo/path/to/your_file.py
https://github.com/your_account/your_repo/blob/your_branch/path/to/your_file.py

Branch Options

Use the --branch (or -b) flag to control which branch appears in the URL:

# Use current branch (default behavior)
$ gwu url
https://github.com/your_account/your_repo/tree/feature-branch/

# Use default branch (main/master) - URL without explicit branch
$ gwu url --branch=default
https://github.com/your_account/your_repo

# Use a specific branch
$ gwu url --branch=main
https://github.com/your_account/your_repo/tree/main/

# Short form
$ gwu url -b develop
https://github.com/your_account/your_repo/tree/develop/

The relpath Subcommand

Print the relative path from the git repository root to the given file or folder.

Basic Usage

# At repository root, prints "."
$ cd /path/to/your_repo
$ gwu relpath
.

# In a subdirectory, prints relative path
$ cd /path/to/your_repo/src/module
$ gwu relpath
src/module

Specify a File or Folder

$ gwu relpath /path/to/your_repo/src/module/file.py
src/module/file.py

Python API Usage

You can also use git_web_url as a Python library:

from pathlib import Path
import git_web_url.api as gwu

# Get URL for a file using current branch
url = gwu.get_web_url(Path("/path/to/your_repo/file.py"))

# Get URL using default branch (main/master)
url = gwu.get_web_url(
    Path("/path/to/your_repo/file.py"),
    branch=gwu.DEFAULT_BRANCH,
)

# Get URL using a specific branch
url = gwu.get_web_url(
    Path("/path/to/your_repo/file.py"),
    branch="feature-branch",
)

Install

git_web_url is released on PyPI, so all you need is to:

$ pip install git-web-url

To upgrade to latest version:

$ pip install --upgrade git-web-url

Table of Content

About the Author

(\ (\
( -.-)o
o_(")(")

Sanhe Hu is a seasoned software engineer with a deep passion for Python development since 2010. As an author and maintainer of 150+ open-source Python projects, with over 15 million monthly downloads, I bring a wealth of experience to the table. As a Senior Solution Architect and Subject Matter Expert in AI, Data, Amazon Web Services, Cloud Engineering, DevOps, I thrive on helping clients with platform design, enterprise architecture, and strategic roadmaps.

Talk is cheap, show me the code:

API Document