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


当前回答

你用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 不重要。

其他回答

只需获取远程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:

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

我认为你可以找到它在.git/config 和远程[“起源”] 如果你没有操纵它。

获取原产地的 IP 地址/主机名称

对于 ssh:// 存储库:

git ls-remote --get-url origin | cut -f 2 -d @ | cut -f 1 -d "/"

關於 git:// repositories:

git ls-remote --get-url origin | cut -f 2 -d @ | cut -f 1 -d ":"

要总结一下,至少有四种方式:

使用官方 Linux 存储库:

最小信息:

$ git config --get remote.origin.url
https://github.com/torvalds/linux.git

$ git ls-remote --get-url
https://github.com/torvalds/linux.git

更多信息:

$ git remote -v
origin    https://github.com/torvalds/linux.git (fetch)
origin    https://github.com/torvalds/linux.git (push)

更多信息:

$ git remote show origin
* remote origin
  Fetch URL: https://github.com/torvalds/linux.git
  Push  URL: https://github.com/torvalds/linux.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

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

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