My company is evaluating bitbucket as our central VCS. We currently use gitlab 7.13.4. We have looked for an automated way to migrate all of our gitlab repos into bitbucket but my searches have come up empty. There are plenty of examples for doing this one at a time, but nothing to do all of them in a batch. With hundreds of repos we'd like to use a process that has a good chance of reliability.

As a bonus is there a way to migrate groups and permissions automatically?


1 Answer 1


You can use the Bit Bucket REST api, here is some Perl I use to import a repository into bitbucket:


use strict;
use warnings;
use Data::Dumper;
use File::Basename;
my $numArgs = $#ARGV + 1;

if($numArgs < 2) {
 die "Usage: $0 [Bit Bucket Project e.g. FW, BDPE] [repo name] [-d dry run (optional)]";

my $bitbucketProject = lc $ARGV[0];
my $repoName = $ARGV[1];
my $dryRun = $ARGV[2];
my %moduleHash;
my $bitBucketServer = "localhost";
my $user = "admin";
my $password = "bitbucket";

print "Bit Bucket Project: $bitbucketProject\n";
print "Repository name: $repoName\n";

sub importRepo {

     my $command = sprintf("curl -u %s:%s -X POST -H \"Content-Type: application/json\" -d '{
     \"name\": \"%s\",
     \"scmId\": \"git\",
     \"forkable\": true
     \}' http://%s:7990/rest/api/1.0/projects/%s/repos", $user, $password, $repoName, $bitBucketServer, $bitbucketProject); 

    if ($dryRun) {
      print "$command\n";
    } else {
    print "Doing import\n";
        system $command;
    my $bitbucketUrl = sprintf("ssh://git\@%s:7999/%s/%s.git", $bitBucketServer, lc $bitbucketProject, $repoName);   
    my $gitCommand = sprintf("cd %s; pwd;  git repack -a -d -f; git push %s --mirror", $repoName, $bitbucketUrl);
    if ($dryRun) {
      print "$gitCommand\n";
    } else {   
       print "Running git\n";
       system $gitCommand;



Then you can wrap around that with a shell script:



if [ $# -ne 2 ]; then
echo "Usage: $0 [Bit Bucket Project] [Path to repos]"
exit 1;

echo "Bit bucket project: $BITBUCKETPROJECT"

    for f in *; do
        if [[ -d $f ]]; then
          echo $f
          ./importRepository.pl $BITBUCKETPROJECT $f 

Assumes that all of your repos have been cloned into the current directory.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .