Automatically clone all repositories defined in conf/gitolite.conf

In this post, I post a simple, hackish script to clone all repositories defined in a gitolite config file. There may be various reasons why one should want to clone a bunch of repositories at a time, e.g., in case one is working with a bigger project composed of several independent components or to simply create a backup of repositories. No matter what the reason is, this script could be handy in such a case:

# Copyright 2013, Ruediger Gad <>
# This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
# To view a copy of this license, visit
# or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
# Script to automatically clone repositories defined in a gitolite config file.
# Example:
# ssh:// [my_gitolite_config.conf]
# The first command line parameter is the URL where the repositories are located at.
# The path to the gitolite config can be given as last command line parameter.
# If the path is not given conf/gitolite.conf is used as default path.
# Please note that this script expects the repo line to start with "repo"
# without any preceding whitespace and to contain exactly one space between
# the "repo" keyword and the path of the repository.
# You can adjust this behavior by tweaking the grep command in the REPOS_LINES assignment.
# This only works for repositories that are explicitly defined via a repo entry.

if [ $# -eq 0 ]
    echo "Please specify at least a server URL where the repositories are located."


if [ $# -eq 1 ]
    echo "Using default path to gitolite config: ${GITOLITE_CONFIG}"
echo "Using ${GITOLITE_CONFIG} to get repo lines."

REPO_LINES=$(grep "^repo [a-Z]" ${GITOLITE_CONFIG} | sed 's/^repo //')

for rl in $REPO_LINES
    if [ $(echo $rl | grep "/") ]
        dir=$(dirname $rl)
        echo "Found repository in subdirectory. Creating parent directories first: $dir"
        mkdir -p $dir
        cd $dir
        echo "Checking out: $rl"
        git clone ${SERVER_URL}/$rl
        cd -
        echo "Checking repository out: $rl"
        git clone ${SERVER_URL}/$rl

This script can be run again after more repositories were added to the gitolite config. It will simply not clone the already checked out repositories again. In this case, you can safely ignore the error messages.
For updating the cloned repositories you can use the script I posted here earlier.

This entry was posted in Snippets and tagged , , , . Bookmark the permalink.

1 Response to Automatically clone all repositories defined in conf/gitolite.conf

  1. hiramhzr says:

    Thanks, works fine

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.