Skip to content

Instantly share code, notes, and snippets.

@alejandrosaenz117
Last active June 13, 2025 15:28
Show Gist options
  • Save alejandrosaenz117/310e0331cee6e2625fb28385aa6b294f to your computer and use it in GitHub Desktop.
Save alejandrosaenz117/310e0331cee6e2625fb28385aa6b294f to your computer and use it in GitHub Desktop.
A python script to clone multiple repositories into a single directory.
# The MIT License (MIT)
# Copyright (c) 2020 Alejandro Saenz
# Copyright (c) 2020 Jonn Callahan
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
# OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import os, sys
import errno
from git import Repo
# Description: This script will clone multiple source code repositories into a single directory
# If cloning via SSH, use the following link to enter pass phrase once:
# https://stackoverflow.com/questions/10032461/git-keeps-asking-me-for-my-ssh-key-passphrase
# Generates progress bar for visual completion of clone
# https://gist.github.com/vladignatyev/06860ec2040cb497f0f3
def progress(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = "=" * filled_len + "-" * (bar_len - filled_len)
sys.stdout.write("[%s] %s%%%s\r" % (bar, percents, status))
sys.stdout.flush()
# Creates a directory using the prompted name.
# If the directory name is not unique, it will prompt the user to update the name accordingly
def create_folder(name):
try:
os.mkdir(name)
return name
except OSError as e:
if e.errno == errno.EEXIST:
print('A directory named "' + name + '" already exists. Please enter a unique directory name: ')
name = raw_input()
return create_folder(name)
else:
raise
directory_name = create_folder(raw_input('Enter a directory name: '))
# Comma delimited list of strings. Add repositories here!
# i.e, repo_list = ['git://URL1', 'git://URL2', 'git://URL3']
repo_list = []
print('Cloning repositories to directory "'+ directory_name +'". Please wait...')
num_repos = len(repo_list)
for idx, repo in enumerate(repo_list):
progress(idx + 1, num_repos)
folder_name = repo.split('/')[-1]
Repo.clone_from(repo, directory_name + '/' + folder_name.split('.git')[0])
print('\nSuccessfully cloned ' + str(len(repo_list)) + ' repositories!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment