如何获取当前仓库的名称和个人/组织以在.gitconfig中使用?

3

我想要做的基本上是创建一个实用工具,可以执行以下命令:

git open

这个命令将在浏览器中打开当前github存储库。如果能够获取存储库名称,那么我只需要使用别名 https://github.com/{用户或组织}/{存储库名称}


1
使用远程URL怎么样? - Code-Apprentice
2个回答

4

试试这个bash函数

适用于Linux:

function git-open-url(){
  xdg-open `git config --get remote.origin.url`
}

针对Mac系统:

function git-open-url(){
  open `git config --get remote.origin.url`
}

0

我看过git-open工具。它很酷,但我只想在我的.gitconfig文件中加一行代码,所以这是我最终做的。

[alias]
    open = "!open https://github.com/$(echo $(git remote get-url origin) | cut -f2 -d\":\")"

运行完美 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接