我在GitHub上拖了一個有幾個福克的項目,但忘記了它是哪個福克。
当前回答
#!/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 ls-remote --get-url [REMOTE]
這比閱讀配置更好;引用 git-ls-remote 的男性頁面:
--get-url 将该远程存储库的 URL 扩展,考虑到任何“url.<base>.insteadOf”配置设置(见 git-config(1)),并将其输出而不与远程存储库进行谈话。
正如 @Jefromi 指出的那样,此选项在 v1.7.5 中添加,并且直到 v1.7.12.2 (2012-09 ) 之前没有文档。
要总结一下,至少有四种方式:
使用官方 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)
获取原产地的 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 ":"
你用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 文件夹的位置:
git config --get remote.origin.url
如果你连接到一个网络,
git remote show origin
它将向您显示一个本地Git存储库原来被克隆的URL。
推荐文章
- “node_modules”文件夹应该包含在git存储库中吗
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 如何运行一个github-actions步骤,即使前一步失败,同时仍然失败的工作
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 在GitHub repo上显示Jenkins构建的当前状态
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?