[英]How to get Git repo url from my server and push directly to it from local dev. terminal?
[英]How to get git repo from url
我有回购git@gitlab.com:alex93ushakov-mail/test.git
。
在Bash中,我想编写一个函数,该函数将git url作为参数并返回存储库名称“ test”。 这个怎么做?
function foo() {
local a="$1" # copy first argument to local variable a
a="${a##*/}" # strip left part including /
echo "${a%.git*}" # strip trailing .git
}
foo "git@gitlab.com:alex93ushakov-mail/test.git"
输出:
test
为了避免尾随换行符:在echo
添加选项-n
您可以尝试使用正则表达式:
s/.+\/(\w+)\\\.git/$+/
不知道bash是否等效于我通常使用的perl,但这可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.