我在GitHub上拖了一個有幾個福克的項目,但忘記了它是哪個福克。
当前回答
获取原产地的 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 ":"
其他回答
这只提供URL,这对脚本目的有用:
git config --get remote.origin.url
alias git-repo="git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g'"
alias git-pr="git config --get remote.origin.url | sed -e 's/:/\//g'| sed -e 's/ssh\/\/\///g'| sed -e 's/git@/https:\/\//g' | sed 's/....$//' | sed -ne 's/$/\/pulls &/p'"
在主目录中将此表达式添加到.zshrc 或.bashrc 文件中。
在此之后,您可以使用如
git-repo
git-pr
使用 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浏览器打开它。
你用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 config -l
它将列出所有有用的信息,如:
user.name=Your Name
user.email=your.name@notexisting.com
core.autocrlf=input
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://github.com/mapstruct/mapstruct-examples
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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下载文件的最新版本的存储库?