我在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 不重要。

其他回答

要补充其他答案:如果远程因某种原因已被更改,因此不反映原来的起源,则重组中的第一个输入(即由命令 git reflog 显示的最后一个输入)应指明重组原来的位置。

吉。

$ git reflog | tail -n 1
f34be46 HEAD@{0}: clone: from https://github.com/git/git
$

(请记住,返回可以被清理,所以这不保证工作。

git remote get-url origin

(Git 远程设置 URL 起源 <newurl>)

See commit 96f78d3 (2015 年 9 月 16 日) by Ben Boeckel (mathstuf). (Merged by Junio C Hamano -- gitster -- in commit e437cbd, 2015 年 10 月 5 日):

远程: 添加 Get-url 子命令 扩展代替Of 是 ls-remote --url 的部分,并且没有办法扩展 pushInsteadOf 也。

get-url:

将 URL 转移到远程. 设置为替代Of 和 pushInsteadOf 在这里扩展. 默认情况下,只有第一个 URL 被列入. 通过“--push”,按 URL 被查询而不是接收 URL. 通过“--all”,所有 URL 被列入远程。


在 git 2.7 之前,你有:

 git config --get remote.[REMOTE].url
 git ls-remote --get-url [REMOTE]
 git remote show [REMOTE]
#!/bin/bash

git-remote-url() {
 local rmt=$1; shift || { printf "Usage: git-remote-url [REMOTE]\n" >&2; return 1; }
 local url

 if ! git config --get remote.${rmt}.url &>/dev/null; then
  printf "%s\n" "Error: not a valid remote name" && return 1
  # Verify remote using 'git remote -v' command
 fi

 url=`git config --get remote.${rmt}.url`

 # Parse remote if local clone used SSH checkout
 [[ "$url" == git@* ]] \
 && { url="https://github.com/${url##*:}" >&2; }; \
 { url="${url%%.git}" >&2; };

 printf "%s\n" "$url"
}

使用:

# Either launch a new terminal and copy `git-remote-url` into the current shell process, 
# or create a shell script and add it to the PATH to enable command invocation with bash.

# Create a local clone of your repo with SSH, or HTTPS
git clone git@github.com:your-username/your-repository.git
cd your-repository

git-remote-url origin

出口:

https://github.com/your-username/your-repository

一个简单的方式是打开.git/config 文件:

cat .git/config

编辑:

vim.git/config 或

纳米.git/config

使用 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浏览器打开它。