[英]git clone an organisation repo with username password on url
So, I have the following situation: 1. have access to an organisations github repo 2. 2fa enabled on github 3. clone works fine in ssh mode and via github web (ie credentials are fine).所以,我有以下情况: 1. 可以访问组织的 github 存储库 2. 在 github 上启用 2fa 3. 克隆在 ssh 模式下和通过 github web 工作正常(即凭据很好)。
What I am trying to do: I am trying to clone a repo on the url like so:我正在尝试做的事情:我正在尝试在 url 上克隆一个 repo,如下所示:
git clone https://mygithubusername:mygithubpwd@github.com/organisationname/org_git_repo.git
but I get back:但我回来了:
remote: Invalid username or password.
fatal: Authentication failed for ..
I am not really sure why.我不确定为什么。 I do this url clone on my personal projects on gitlab, and it has always worked fine, so, I am perplexed why I get this error.
我在 gitlab 上的个人项目上执行了这个 url 克隆,它一直运行良好,所以,我很困惑为什么会出现这个错误。
Worth saying that I do have a special char in my pwd ( #
) and I encode this using %23
like so:值得一提的是,我的密码 (
#
) 中确实有一个特殊字符,我使用%23
进行编码,如下所示:
git clone https://mygithubusername:mygithubpwd%23001@github.com/organisationname/org_git_repo.git
Any suggestions as to why this fails?关于为什么会失败的任何建议? Been looking for a couple of days now for a solution!
已经找了几天的解决方案!
OK - so I have found a solution to this.好的 - 所以我找到了解决方案。 It looks like when you use 2FA, you cannot simply just do clone on the cmd line using un/pwd combo.
看起来当您使用 2FA 时,您不能简单地使用 un/pwd 组合在 cmd 行上进行克隆。
The solution is to generate a token on github and then use this token on the cmd instead of pwd.解决办法是在github上生成一个token,然后在cmd上使用这个token,而不是pwd。 This solves it.
这就解决了。
Hopefully this helps someone.希望这有助于某人。
Maybe you can try this bash script, which I created: https://github.com/hobbymarks/orgclone也许你可以试试这个我创建的 bash 脚本: https : //github.com/hobbymarks/orgclone
Note: the script requires Github CLI https://cli.github.com/ ,so you need install Github CLI firstly.注意:脚本需要 Github CLI https://cli.github.com/ ,所以你需要先安装 Github CLI。
In fact, it is only a bash script, so you can directly run orgclone.sh.其实只是一个bash脚本,直接运行orgclone.sh即可。 or you can copy the code below to create your own script:
或者您可以复制下面的代码来创建自己的脚本:
#!/bin/bash
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
LIMIT=500
# Help
Help()
{
# Display Help
echo "git clone all the repos of an organization."
echo
echo "Syntax: orgClone.sh [-l NAME | -r NAME |h]"
echo "options:"
echo "l List all repos in the NAME organization one bye one."
echo "r Run git clone repo in the NAME organization one bye one."
echo "h Print this Help."
echo
}
# Main program
# Orgnization Name
orgName=""
# List all repos in the org
ListRepos()
{
echo "********** all repos in $orgName:"
repos=$(gh repo list $orgName -L $LIMIT | cut -f 1 | cut -d "/" -f 2)
idx=1
while IFS= read -r line
do
if [[ -d $line ]] || [[ -d $line@$orgName ]]
then
echo -e "${GREEN}==>${NC}"$idx:$line
else
echo -e "${RED}-->${NC}"$idx:$line
fi
((idx = idx + 1))
done <<<"$repos"
}
# Git clone all repos in the org
CloneRepos()
{
echo "********** all repos in $orgName:"
repos=$(gh repo list $orgName -L $LIMIT |cut -f 1 | cut -d "/" -f 2)
idx=1
while IFS= read -r line
do
if [[ -d $line ]] || [[ -d $line@$orgName ]]
then
echo -e "${GREEN}==>${NC}"$idx:$line
else
echo -e "${RED}-->${NC}"$idx:$line
git clone https://github.com/$orgName/$line.git
fi
((idx = idx + 1))
done <<<"$repos"
}
# Process the input options.
# Get the options
while getopts ":hr:l:" option; do
case $option in
h) # Display Help
Help
exit;;
r) # Git clone all repos in the org
orgName=$OPTARG
CloneRepos
exit;;
l) # List all repos
orgName=$OPTARG
ListRepos
exit;;
\?) # Invalid option
echo "Error: Invalid option."
exit;;
esac
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.