[英]How can I determine username from the Url of a remote repository?
Before to pull a project from Git repository, I want to check if the git user name is in the URL of remote repository. 在从Git存储库中提取项目之前,我要检查git用户名是否在远程存储库的URL中。
Eg: https://usernameAA@remote => if git username == "usernameAA" OK to pull. 例如: https:// usernameAA @ remote =>如果git username ==“ usernameAA”确定可以拉。
I can get the URL with git ls-remote --get-url
and finding username with git config user.name
我可以使用git ls-remote --get-url
并使用git config user.name
查找用户名
How can I determine if username from the Url of a remote repository is equal to username to associate commits? 如何确定远程存储库Url中的用户名是否等于关联提交的用户名?
Why not extract the username from the url returned by git ls-remote --get-url
: 为什么不从git ls-remote --get-url
返回的URL中提取用户名:
username=$(git ls-remote --get-url origin | cut -d@ -f1 | cut -d/ -f3| cut -d: -f1)
The last cut -d: -f1
is in the (improbable) case where the url includes the username and password: http://username:password@domain.com/...
last cut -d: -f1
是(不太可能)的情况,其中URL包含用户名和密码: http://username:password@domain.com/...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.