我在GitHub上拖了一個有幾個福克的項目,但忘記了它是哪個福克。
当前回答
使用 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浏览器打开它。
其他回答
打印自愿命名的远程 fetch URL:
git remote -v | grep fetch | awk '{print $2}'
此将打印您的所有远程的Fetch/Push URL:
git remote -v
#!/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 remote -v
出口:
origin https://github.com/torvalds/linux.git (fetch)
origin https://github.com/torvalds/linux.git (push)
事实上,我把它放在一个名为 s 的 alias 中,它:
git remote -v
git status
您可以添加到您的个人资料:
alias s='git remote -v && git status'
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
推荐文章
- 在Markdown Jekyll中使用图像说明
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 如何将文件附加到GitHub问题?
- 真实的恶魔
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时
- git reflog和log有什么区别?
- git推挂在Total line之后
- 重命名git子模块
- 如何添加谷歌分析跟踪ID到GitHub页面