Thursday 19 March 2015

Transferring Existing Repositories to GitLab

Here at Appdragon we have some of the best coders using the industry's best SDK tools and applications. One of the apps we use is GitLab.  Here, our system admin, Musa, provides a quick change of pace from our usual blogs and dives into something a little more technical.

We used to use Gerrit Code Review along with git-web before migrating to GitLab. So we had to transfer all our existing repositories to GitLab. This tutorial can also be used for migrating from other git based issue tracking systems. The GitLab documentation says to put all your bare repositories, the ".git" directories, into this location - "/home/git/repositories" and then use the import command. But this doesn't do the job, it only creates blank empty projects under the Admin group with no source files or previous issues. So to solve this, just follow the steps below -

?
1
2
3
4
5
6
7
8
# Copy all the bare repositories from Gerrit to GitLab
# You should change $newdir into something you prefer
# The command is going to create a new directory inside the repositories directory
sudo cp -R /usr/local/gerrit2/git /home/git/repositories/$newdir
# Change ownership of the directory
sudo chown -R git:git /home/git/repositories/$newdir

This is for Gitlab versions 6 and less
?
1
2
3
4
5
6
7
# And now you can run this command, provided by the GitLab Team
# Change to root user and go to GitLab's directory
cd /home/git/gitlab
sudo su
sudo -u git -H bundle exec rake gitlab:import:repos RAILS_ENV=production

For Gitlab versions 7 and onwards (That is, if you've installed Gitlab using the debian package)
?
1
2
# Just run the following command
sudo gitlab-rake gitlab:import:repos
When you run the above command GitLab is going to create a new group named $newdir (i.e., the directory's name) and import the repositories perfectly. Now you can access GitLab with your admin account and access all the projects under the newly created group.

Thanks for reading this, I hope this slight modification helps you guys. To read more of Musa's hints and tips visit his own blog at http://www.redmoses.me.

No comments:

Post a Comment