首页 > 解决方案 > 检查“远程”是否确实是 git 远程

问题描述

假设我有一个这样的字符串列表:

remotes/origin/master
remotes/origin
origin/master
origin

如何判断字符串的开头是否是有效的遥控器?例如,

remotes/origin
origin

一般来说,两者都应该是有效的遥控器,对吧?怎么确定呢?

标签: gitgithubgitlabgit-remote

解决方案


好吧,回答实际问题(而不是我从示例中看到的我期望看到的问题):

git config --local --get-regexp "^remote\\.$yourname\\.url" >&- \
&& echo it\'s a remote

应该很好吃。我为常用选项组合提供别名,我在这里使用的是

git config --global alias.grl '!f() { git config --local --get-regexp "${@-.}"; }; f'

所以我实际用于自己工作的测试是

git grl "^remote\\.$yourname\\.url" >&-  && echo it\'s a remote

要测试远程跟踪分支名称,我在第一次尝试时回答的问题是

[[ `git rev-parse --symbolic-full-name $anything` = refs/remotes/* ]] \
&& echo it\'s a remote

或者

case `git rev-parse --symbolic-full-name $anything` in
refs/remotes/*)  echo yes ;;
esac

如果你不使用bash.


推荐阅读