Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hackery to migrate existing GIT repositories to BitBucket as the master origin. Say you have a directory of folders, each with a git repository, that need to be created as private repositories and pushed up. This does that.
#!/bin/bash
# Get your credentials set in your environment before you run:
# export BB_USER="my_username"
# export BB_P="MySERCRETP4ss"
# export BB_OWNER="my_username_or_team"
for f in $(find -type d -path '.*git' |cut -d'.' -f2|sed 's:/::g'); do
g=$(curl -s -u $BB_USER:$BB_P "https://bitbucket.org/api/1.0/repositories/$BB_OWNER/$f")
rg=$(echo "$g" | grep -c error)
if [ "$rg" -eq 1 ];
then
echo "Creating repository for [$f]"
r=$(curl -s -u $BB_USER:$BB_P -X POST "https://bitbucket.org/api/1.0/repositories" -d "name=$f&slug=$f&scm=git&owner=$BB_OWNER&is_private=true&language=php")
rr=$(echo "$r" | grep -c error)
if [ "$rr" -eq 0 ];
then
echo " ...Done!"
else
echo " ... uh oh. Failed: $r"
fi
else
echo "Repository exists for [$f]"
echo "Getting BitBucket in place..."
cd "./$f"
git remote add origin "ssh://git@bitbucket.org/$BB_OWNER/$f.git"
# http://stackoverflow.com/a/10479068/1130528
git push -u origin --all
git push -u origin --tags
echo " ...Done!"
cd ..
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.