• Portretfoto van Kees Hink
    Kees Hink

Mass migrating repositories to GitLab

GitLab's automatic repository creation makes migrating git repositories a breeze.

I seem to remember, from a long distant past, that mass creation of repositories was time-consuming. Even now, a quick Google search will point you first to Gitlab's "create project" page. Even the "Create a repository" instruction does not mention a command line alternative to creating a repository in the website.

But let's be clear: Once your GitLab project is set up, individual repositories can be added by a simple git push!

This makes taking over a project with several repositories a lot quicker. Consider this shell one-liner (which I split out over lines for your reading convenience). I assume all the repos are in a file repos.txt, one repo per line.

for repo in $(cat repos.txt);
do git clone $repo --mirror;
slug=$(echo $repo | sed -n 's/.*\/\(.*\).git/\1/p');
cd $slug.git;
git remote add your_remote git@gitlab.com:your_organization/your_project/$slug.git;
git push your_remote --mirror;
cd -;

Some notes here:

  • --mirror will fetch or push all branches. It will not check out the master branch, as git clone will do by default. It will also append .git to the repo directory name.
  • sed -n 's/.*\/\(.*\).git/\1/p' will give you the name of the repo.
We love code


Wij maken gebruik van cookies. Meer hierover lees je in onze Privacy- cookieverklaring.