Ist es möglich, mehrere Git-Repositorys mit einem Befehl zu git clone
en (zum Beispiel: git clone "1.git,2.git,3.git.."
in einem lokalen Verzeichnis)?
Skriptbeispiele finden Sie wie dieses :
Ich habe diese Datei namens "Klon" mit URLs mehrerer Git-Repos (aus djangosites.com . Awesome Site. Muss besuchen)
Ausschnitt:
$ cat clone
https://github.com/igorsobreira/igorsobreira.com https://github.com/ella/ella https://github.com/divio/Django-cms/ https://github.com/palewire/palewire.com https://github.com/jabapyth/jfcom https://github.com/humanfromearth/snippify https://github.com/scaphilo/koalixcrm https://github.com/jlev/Boycott-Toolkit https://github.com/jbalogh/zamboni/ https://github.com/ASKBOT/askbot-devel https://github.com/emesik/djiki https://github.com/vicalloy/LBForum https://github.com/agiliq/agiliq https://github.com/bartTC/dpaste.de https://github.com/bartTC/Django-paste https://github.com/bartTC/dpaste_de/ https://github.com/fotochest/fotochest https://esp.mit.edu/git/esp-project.git https://github.com/titan2x/bashoneliners.git
Anscheinend ist es schwieriger, mehrere Repos gleichzeitig zu klonen (
git clone <repo1> <repo2> ... <repon>
funktioniert nicht). Also habe ich diesen kurzen Code geschrieben, damit es funktioniert:Code:
atm in /home/atm/git/Django_repos
$ for f in `cat clone`; do `git clone $f`; done
Sie finden viele weitere auf Gist.github.com , wie dieses , um alle Ihre Repos aus GitHub zu klonen:
#!/bin/bash
#
# Copyright 2011, Tim Branyen @tbranyen <[email protected]>
# Dual licensed under the MIT and GPL licenses.
#
# Automatically clone single or multiple repos into a folder,
# great for setting up a git projects folder.
#
# Install: curl https://Gist.github.com/raw/902154/github.sh > /usr/local/bin/gh
# chmod +x /usr/local/bin/gh
#
# Internal properties
[email protected]:
GITHUB_USERNAME=$(git config --global github.user)
function main {
# Improperly configured user
detect_user
# Missing arguments
args=$1
if [ -z $args ]; then
echo '
gh: try ''`gh --help`'' for more information
'
exit
fi
# Display help text
if [ $args = '--help' ]; then
echo '
Clone repos from your GitHub
gh repo1 repo2
Clone repos from others GitHub
gh username/repo1 username/repo2
Clone mixed repos:
gh repo1 username/repo2
Clone line separated repos from file:
cat file | xargs gh
'
exit
fi
# Parse arguments and clone repos.
find_repos
}
function detect_user {
# If no username configured, attempt to pull from git --config
if [ -n "$GITHUB_USERNAME" ]; then
USERNAME=$GITHUB_USERNAME
else
echo '
gh: missing username
configure username with ''`git config --global github.user username`''
'
exit
fi
}
function find_repos {
for repo in $args; do
# If a user provides the parameter username/repo pull in that specific repository.
if [ `awk -v repo="$repo" -v delimit="/" 'BEGIN{print index(repo,delimit)}'` -ne 0 ]; then
echo "Pulling in $repo";
git clone $GITHUB_PREFIX$repo.git
# Default to you.
else
echo "Pulling in $USERNAME/$repo";
git clone $GITHUB_PREFIX$USERNAME/$repo.git
fi
done
}
main $*
So fast für mich gelöst:
git clone https://myrepo.com/folder.git && \
git clone https://myrepo.com/folder2.git && \
git clone https://myrepo.com/folder3.git
Dies lässt sich mit einem Code-Editor wie Sublime oder VSCode einfacher erstellen.
Der einzige Nachteil für mich: Wenn Sie Ihre Anmeldeinformationen nicht gespeichert haben, müssen Sie sie immer wieder eingeben.
Ich habe ein Beispielskript für mein Projekt erstellt. Unser Projekt umfasst viele Repositories, die geklont werden müssen, wenn eine frische Person dem Team beitritt.
Hier ist also der Inhalt des Skripts, das Sie in einige ausführbare Dateien speichern und ausführen können.
echo -n Please Enter your GitHub Username:
read username
echo -n Please Enter your GitHub Password
read -s password // doesn't echoes the password on screen
git clone
https://$username:[email protected]/location/reponame1.git
https://$username:[email protected]/location/reponame2.git
....
https://$username:[email protected]/location/reponamen.git
Es ist leise nützlich, um langweilige manuelle Anstrengungen zu vermeiden und sicherzustellen, dass alle erforderlichen Projekte auf einmal geklont werden.
Hoffe, meine Antwort hilft auch jemand anderem.
Nachdem ich diesen und andere Beiträge gelesen hatte, endete ich mit diesem Skript.
Ich benötigte eine Authentifizierung in meiner lokalen Umgebung für meine Repositorys.
Das Skript fragt Sie also nach Benutzer, Kennwort und einer Option, falls Sie sich Ihre Anmeldeinformationen im Repository merken möchten.
Aus Sicherheitsgründen lösche ich den Benutzer und das Passwort aus der Konfigurationsdatei in git. (Nicht sicher, ob diese Anmeldeinformationen an einem anderen Ort gespeichert sind)
#!/bin/bash
#
#This script is intended to be used with repositories that need authentication
#
#Funtion to erase the $username:[email protected] from the config file from git in the repo
function erase_user_pass() {
printf "${green}lets clean $1 from $2 \n${normal}"
sed -i 's/'"$1"'/'""'/g' $2
}
#function to download the repo
#1-clone the repo
#2-fix the config file by deleting the user and password
#3-execute the git command to automatically store the credentials if the user answer yes on the startup
#
# param 1 = name of the repo
# param 2 = string to complet the url of the repo
#
# example repo in https://git.something.com/yourcompany/your.project.git
#
# the param1 should be your.project
# the param2 should be git.something.com/yourcompany/your.project.git (without 'https://')
#
# download_repo 'your.project' 'git.something.com/yourcompany/your.project.git'
#
function download_repo() {
path=$(pwd)
printf "${blue}\n Importing $1\n\n${normal}"
git clone https://$username:[email protected]$2
file="$(pwd)/$1/.git/config"
replace_string="$username:[email protected]"
erase_user_pass $replace_string $file
cd ./$1
if [ "$STORE_OK" == 'Yes' ]
then
printf "${green} store credentials for the repo $1 \n${normal}"
git config credential.helper store
fi
cd $path
}
blue=$(tput setaf 4)
green=$(tput setaf 2)
normal=$(tput sgr0)
echo -n Please Enter your GitHub Username:
read username
echo -n Please Enter your GitHub Password:
read -s password
printf "\n\nDo you want to store your credentials locally?:"
STORE_OK=
select STORE_OK in Yes No
do
case $STORE_OK in
'') echo 'Please enter 1 for Yes, or 2 for No.';;
?*) break
esac
done
printf "${blue}\n\n lets import your repos\n\n${normal}"
# repo 1 https://git.something.com/yourcompany/your.project.git
download_repo 'your.project' 'git.something.com/yourcompany/your.project.git'
# repo 2 https://git.something.com/yourcompany/your.project2.git
download_repo 'your.project2' 'git.something.com/yourcompany/your.project2.git'
printf "${blue}\n Enjoy :)"
exit 0
Sie sollten die Aufrufe von download_repo ersetzen müssen, um auf Ihre Repositorys zu verweisen. Diese sind gefälscht.
Grüße und danke an andere antworten.
Sie können eine Mischung von Lösungen verwenden.
Verwenden Sie git credential.helper, um ein Cache-Timeout festzulegen (siehe this ). Dann können Sie ein Skript/eine Liste verwenden, wie sie von Fábio vorgeschlagen wird. Auf diese Weise müssen Sie Ihre Anmeldeinformationen nur einmal eingeben (normalerweise, es sei denn, ein Klon dauert länger als das Zeitlimit für den Cache).
git config --global credential.helper 'cache timeout 3600'
git clone https://[email protected]/myproject/myrepo.git
### password should be prompted
git clone https://[email protected]/myproject/mysecondrepo.git
### look ma, no password Prompt!
git clone https://[email protected]/myproject/mythirdrepo.git
git clone https://[email protected]/myproject/myfourthrepo.git
git clone https://[email protected]/myproject/andsoforthrepo.git
Das ist immer noch sequentiell, aber es hilft und ist ziemlich einfach, IMHO.