简体   繁体   English

如何使用 Windows 命令行在 Web 上打开当前的 GitHub 分支?

[英]How can I open the current GitHub branch on Web using Windows command line?

I had this command working on my Mac/Linux (Terminal) with OhMyZsh, but once I moved to Windows, I wasn't sure how to update it using Cmdr/ConEmu shell.我使用 OhMyZsh 在我的 Mac/Linux(终端)上运行了这个命令,但是一旦我转移到 Windows,我不确定如何使用 Cmdr/ConEmu shell 更新它。

Basically, I want an alias that is like "goweb" that will open my default browser to the current branch on GitHub.基本上,我想要一个类似于“goweb”的别名,它将打开我的默认浏览器到 GitHub 上的当前分支。 I'm fine assuming a particular repo.假设有一个特定的回购,我很好。 Maybe a later enhancement would pull that as well using, eg, default remote or the like..也许以后的增强功能也会使用例如默认遥控器等来拉动它。

This answer hard-codes the repo URL and just appends the current branch. 此答案对回购URL进行硬编码,并仅附加当前分支。 Add this to your user-aliases.cmd (if using cmdr) or wherever you can set aliases. 将此添加到user-aliases.cmd(如果使用cmdr)或可以设置别名的任何位置。

goweb=@echo off && for /f %i in ('git rev-parse --abbrev-ref HEAD') do start https://<pathToRepo>/tree/%i

Replace with the URL to your repo. 替换为您的仓库的URL。

Once this is in there, you can just type goweb from your CLI and it should open it for ya. 进入该目录后,您只需从CLI键入goweb ,它将为您打开它。 Saves a few clicks when you need to do something on your current branch on GH. 当您需要在GH的当前分支上执行某些操作时,可以节省一些单击次数。

Another approach is to use the GitHub command-line gh , specifically gh browse , introduced with Gh 1.12.0 (June 2021)另一种方法是使用 GitHub 命令行gh ,特别是gh browse ,随 Gh 1.12.0(2021 年 6 月)一起引入

Open the GitHub repository in the web browser.在 Web 浏览器中打开 GitHub 存储库。

 gh browse [<number> | <path>] [flags]

Example例子

$ gh browse main.go --branch main # => Open main.go in the main branch

If you just want the remote URL, add the --no-browser option .如果您只需要远程 URL,请添加--no-browser选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM