我在GitHub上拖了一個有幾個福克的項目,但忘記了它是哪個福克。


当前回答

上流的远程可能不会被称为“起源”,所以这里有一个变量:

remote=$(git config --get branch.master.remote)
url=$(git config --get remote.$remote.url)
basename=$(basename "$url" .git)
echo $basename

或:

basename $(git config --get remote.$(git config --get branch.master.remote).url) .git

对于更有用的变量,有:

$ git config -l

其他回答

Git URL 将位于 Git 配置文件中,值相当于关键 URL。

对于 Mac 和 Linux,请使用下面的命令:

cd project_dir
cat .git/config | grep url | awk '{print $3}'

在 Windows 中,在任何文本编辑器中打开下面的文件,并找到关键URL的值。

project_dir/.git/config

注意: 即使您离线或远程 Git 服务器已被删除,这也将工作。

只需获取远程URL:

git config --get remote.origin.url

如果您需要完整的输出,并且您正在网络上,可以到达原产地的远程雷波:

git remote show origin

当使用 git clone (从 GitHub,或任何源存储器为该材料) 的默认名称为 clone 的来源是“起源”。使用 git 远程显示将显示有关这个远程名称的信息。

C:\Users\jaredpar\VsVim> git remote show origin
* remote origin
  Fetch URL: git@github.com:jaredpar/VsVim.git
  Push  URL: git@github.com:jaredpar/VsVim.git
  HEAD branch: master
  Remote branches:

如果你想在脚本中使用值,你会使用这个答案中列出的第一个命令。

这只提供URL,这对脚本目的有用:

git config --get remote.origin.url

使用 git 远程显示起源,您必须在项目目录中,但如果您想从其他地方确定 URL 您可以使用:

cat <path2project>/.git/config | grep url

如果您需要这个命令经常,您可以在 MacOS 中的.bashrc 或.bash_profile 中定义一个 alias。

alias giturl='cat ./.git/config | grep url'

因此,您只需要在 Git 根文件夹中呼叫 giturl 以便简单地获得其 URL。


如果你延伸这个 alias 如此

alias giturl='cat .git/config | grep -i url | cut -d'=' -f 2'

你只得到平坦的URL没有先前的

“URL”

url=http://example.com/repo.git

您在使用中获得更多机会:

例子

在 Mac 上,您可以打开 $(giturl) 以在默认浏览器中打开 URL。

或Chrome $(giturl)在Linux上使用Chrome浏览器打开它。

你用SSH克隆来克隆你的存储库。

git config --get remote.origin.url
git@gitlab.com:company/product/production.git

但是,您想要在浏览器中打开或分享一个 HTTP URL:

git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g'

https://gitlab.com/company/product/production.git

GitHub 或 GitLab 不重要。