如何在Windows Cmdr/ConEmu中配置goweb别名打开当前GitHub分支网页?
goweb alias in Cmder/ConEmu to open your GitHub branch page Got it, let's walk through setting up that goweb alias you need in Cmder or ConEmu. We'll start with a fixed repository (as you requested) and then add the auto-detection for remote repos later.
Step 1: Create a batch script for the goweb functionality
First, we'll make a small batch script that fetches your current Git branch and opens the right GitHub page. Here's how:
- Open Notepad and paste this code (replace
your-usernameandyour-repowith your actual GitHub repo details):
@echo off setlocal :: Grab the current Git branch name for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set BRANCH=%%i :: Your fixed repository URL set REPO_URL=https://github.com/your-username/your-repo :: Build the full branch page URL set PAGE_URL=%REPO_URL%/tree/%BRANCH% :: Open the URL in your default browser start "" "%PAGE_URL%" endlocal
- Save this file as
goweb.bat. - Move the file to
%CMDER_ROOT%\bin(if using Cmder) — this directory is already in your Cmder PATH, so the script will be accessible anywhere. If you're using plain ConEmu, add the folder containinggoweb.batto your system PATH.
Step 2: Set up the alias (optional but clean)
Cmder lets you define aliases in its config file to keep things consistent with your Oh My Zsh workflow:
- Open Cmder, then press
Win + Alt + Pto open the settings. - Go to
Startup > Tasks, or directly edit the user aliases file at%CMDER_ROOT%\config\user_aliases.cmd. - Add this line to the file:
goweb=goweb.bat $*
- Save the file and restart Cmder. Now you can just type
gowebin any Git repo (your fixed one) to open the current branch's GitHub page.
Step 3: Optimize for auto-detecting remote repos
To make this work with any repo (instead of a fixed one), update your goweb.bat script to automatically pull the remote repository URL from Git:
@echo off setlocal :: Get current branch for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set BRANCH=%%i :: Get the origin remote URL for /f "tokens=*" %%i in ('git config --get remote.origin.url') do set REMOTE_URL=%%i :: Convert SSH URLs to HTTPS (so it works in the browser) set HTTPS_URL=%REMOTE_URL:.git=% set HTTPS_URL=%HTTPS_URL:git@github.com:=https://github.com/% :: Build the branch page URL set PAGE_URL=%HTTPS_URL%/tree/%BRANCH% :: Open in default browser start "" "%PAGE_URL%" endlocal
This script will handle both HTTPS and SSH remote URLs, so it works no matter how you cloned your repo.
Notes for ConEmu users
If you're using plain ConEmu without Cmder, you can set the alias using doskey directly in your ConEmu startup task:
- Open ConEmu settings (
Win + Alt + P). - Go to
Startup > Tasks, edit your default shell task. - Add this line at the end of the command list:
doskey goweb=goweb.bat $*
Save and restart ConEmu, and the alias will work globally.
内容的提问来源于stack exchange,提问作者Ambrose Little

