我在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)
现在应该注意到,这并不一定与源的远程存储库相同,但在许多情况下,这将是足够的。
其他回答
这只提供URL,这对脚本目的有用:
git config --get remote.origin.url
简短答案:
$ git remote show -n origin
或者,一个纯粹的快速脚本的替代品:
$ git config --get remote.origin.url
一些信息:
你想要起源正确吗? $ git 远程显示起源更好,只显示起源,但需要太长时间(测试在 git 版本 1.8.1.msysgit.1)。
我结束了: $ git 远程显示 -n 起源,似乎是最快的. 与 -n 它不会捕捉远程头(AKA 分支)。 你不需要这种类型的信息,对吗?
http://www.kernel.org/pub//software/scm/git/docs/git-remote.html
您可以在所有 3 个版本中使用 <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk> <unk>
如果你需要纯粹的速度,那么使用:
$ git config --get remote.origin.url
谢谢 @Jefromi 提到这一点。
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]
获取原产地的 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 ":"
#!/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添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- 只用GitHub动作在特定分支上运行作业
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 是否有一个链接到GitHub下载文件的最新版本的存储库?