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
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 email@example.com:your_organization/your_project/$slug.git; git push your_remote --mirror; cd -; done
Some notes here:
--mirrorwill fetch or push all branches. It will not check out the master branch, as
git clonewill do by default. It will also append
.gitto the repo directory name.
sed -n 's/.*\/\(.*\).git/\1/p'will give you the name of the repo.