Skip to content

Instantly share code, notes, and snippets.

@kostajh
Created February 27, 2014 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kostajh/9249937 to your computer and use it in GitHub Desktop.
Save kostajh/9249937 to your computer and use it in GitHub Desktop.
Migrate repositories from gitolite (or somewhere else) to Bitbucket
#!/bin/bash
# Usage: ./bitbucket-migrate.sh repos.txt
#
# repos.txt should have one repository per line.
echo "Reading $1"
while read line
do
repo=$line
echo "###"
echo "Processing $repo"
git clone --bare git@git.designhammer.net:$repo
cd $repo.git
echo "Creating repo in Bitbucket"
curl --user USER:PASSWORD https://api.bitbucket.org/1.0/repositories/ --data name=$repo --data is_private=true --data owner=designhammer
echo "Pushing mirror to bitbucket"
git push --mirror git@bitbucket.org:designhammer/$repo.git
cd ..
echo "Removing $repo.git"
rm -rf "$repo.git"
echo "Waiting 5 seconds"
echo "###"
sleep 5;
done < $1
exit
@alex-ong
Copy link

alex-ong commented Mar 15, 2020

Updated for 2020:

The API changed so i wrote a new thing. Also, bitbucket only supports lowercase names for repositories; our company had mixed case.
This converts the git repo name to lower case, while maintaining mixed case in the project name
Also note that YOURTEAMNAME is case sensitive, you need to create a team and project first inside bitbucket.

#!/bin/bash

# Usage: ./bitbucket-migrate.sh repos.txt
#
# repos.txt should have one repository per line.

echo "Reading $1"

while read line
do
        repo=$line
        repol=${repo,,}
        echo $repol
        echo "###"
        echo "Processing $repo"        
        git clone --mirror git@git.icinema.com:$repo
        cd $repo.git        
        echo "Creating repo in Bitbucket"
        data='{"language":"c#","scm":"git","has_wiki":"true","is_private":"true","fork_policy":"no_public_forks","project":{"key":"GEN"},"name":"'
        data2=$repo
        data3='"}'
        data="${data}${data2}${data3}"
        curl -X POST -u user@username.com:PASSWORD -H "Content-Type: application/json" https://api.bitbucket.org/2.0/repositories/YOURTEAMNAME/$repol -d $data
        echo "Pushing mirror to bitbucket"
        git push --mirror git@bitbucket.org:YOURTEAMNAME/$repol.git 
        cd ..
        rm -rf $repo.git
        echo "Removing $repo.git"
        echo "Waiting 5 seconds"
        echo "###"
        sleep 5;
done < $1

exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment