如何从远程存储库的Url中确定用户名?

时间:2016-09-29 06:21:55

标签: git github git-remote

在从Git存储库中提取项目之前,我想检查一下git用户名是否在远程存储库的URL中。

例如:https://usernameAA@remote =>如果git username ==“usernameAA”可以拉。

我可以使用git ls-remote --get-url获取网址,并使用git config user.name

查找用户名

如何确定远程存储库的Url中的用户名是否等于用户名以关联提交?

1 个答案:

答案 0 :(得分:2)

为什么不从git ls-remote --get-url返回的网址中提取用户名:

username=$(git ls-remote --get-url origin | cut -d@ -f1 | cut -d/ -f3| cut -d: -f1)

last cut -d: -f1处于(不太可能)的情况,其中网址包含用户名密码:http://username:password@domain.com/...

相关问题