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


当前回答

如果你不知道一个分支的上流远程的名称,你可以首先通过检查当前分支的上流分支名称来查看它。

git rev-parse --symbolic-full-name --abbrev-ref @{upstream}

这表明,上流的分支是当前分支的来源,这可以被分配,以获得远程名称如下:

git rev-parse --symbolic-full-name --abbrev-ref @{upstream} | cut -d / -f 1

现在拿到它,并将其粘贴到 git ls-remote,你会得到上流的远程的URL,这是当前分支的来源:

git ls-remote --get-url \
  $(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} | cut -d / -f 1)

现在应该注意到,这并不一定与源的远程存储库相同,但在许多情况下,这将是足够的。

其他回答

打印自愿命名的远程 fetch URL:

git remote -v | grep fetch | awk '{print $2}'

只需远程 URL:

git config --get remote.origin.url

要了解有关特定远程的详细信息,请使用

git remote show [remote-name] command

查看远程URL:

git remote show origin

要查看您在哪里放置.git 文件夹:

git config --get remote.origin.url

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

使用官方 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)

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

吉。

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

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

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

git config --get remote.origin.url