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).
What I am trying to do: I am trying to clone a repo on the url like so:
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.
Worth saying that I do have a special char in my pwd ( #
) and I encode this using %23
like so:
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.
The solution is to generate a token on github and then use this token on the cmd instead of pwd. This solves it.
Hopefully this helps someone.
Maybe you can try this bash script, which I created: https://github.com/hobbymarks/orgclone
Note: the script requires Github CLI https://cli.github.com/ ,so you need install Github CLI firstly.
In fact, it is only a bash script, so you can directly run 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.