Skip to content

Instantly share code, notes, and snippets.

@mhshimul
Forked from kostajh/migrate-bitbucket.sh
Last active April 28, 2018 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhshimul/7ab98724d2b77a80e44e6cc9561f4ca3 to your computer and use it in GitHub Desktop.
Save mhshimul/7ab98724d2b77a80e44e6cc9561f4ca3 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 user@<githost>:$repo
cd $repo.git
echo "Creating repo in Bitbucket"
curl -X POST -u <user>:<password> "https://api.bitbucket.org/2.0/repositories/<organization>/$repo" -H "Content-Type: application/json" -d '{"scm": "git" "is_private": true, "fork_policy": "no_forks", "project": {"key": "<project_key>"}}'
echo "Pushing mirror to bitbucket"
git push --mirror git@bitbucket.org:<organization>/$repo.git
cd ..
echo "Removing $repo.git"
rm -rf "$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