Skip to content

Instantly share code, notes, and snippets.

@shanerk
Forked from leosoto/bb2gh.sh
Created December 28, 2018 20:04
Show Gist options
  • Save shanerk/a67d5027bc0a03f3deef27079fdee6e3 to your computer and use it in GitHub Desktop.
Save shanerk/a67d5027bc0a03f3deef27079fdee6e3 to your computer and use it in GitHub Desktop.
Moves all your organization's bitbucket repositories to GitHub. Note that when a repository is correctly uploaded to GitHub it is *removed* from BitBucket. Requires https://bitbucket.org/zhemao/bitbucket-cli/. Set the variables BB_* with your bitbucket credentials and GH_* variables with your GitHub credentials.
env.sh
*.git
#!/bin/bash
set -e
repos=$(bb list -u $BB_USERNAME -p $BB_PASSWORD --private | grep $BB_ORG | cut -d' ' -f3 | cut -d'/' -f2)
for repo in $repos; do
echo
echo "* Processing $repo..."
echo
git clone --bare https://[email protected]/$BB_ORG/$repo.git || echo "Error cloning BB $repo"
cd $repo.git || echo "Can't access directory $repo.git..."
echo
echo "* $repo cloned, now creating on github..."
echo
curl -u $GH_USERNAME:$GH_PASSWORD https://api.github.com/orgs/$GH_ORG/repos -d "{\"name\": \"$repo\", \"private\": true}"
echo
echo "* mirroring $repo to github..."
echo
git push --mirror https://[email protected]/$GH_ORG/$repo.git || "Error pushing to Github $repo"
# bb delete -u $BB_USERNAME -p $BB_PASSWORD --owner $BB_ORG $repo
cd ..
done
@shanerk
Copy link
Author

shanerk commented Dec 28, 2018

Usage:

$ export GH_USERNAME=shanekenyon87
$ export GH_PASSWORD=****
$ export GH_ORG=redargyle
$ export BB_USERNAME=shanekenyon87
$ export BB_PASSWORD=****
$ export BB_ORG=redargyle
$ ./bb2gh.sh

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