Last active
January 8, 2019 15:37
-
-
Save wheresalice/96367ef6384b0d24179d27cfc617457c to your computer and use it in GitHub Desktop.
Backup your github repos to Bitbucket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: change username:password to either an app-password or your actual password | |
# Change WheresAlice to your actual username on Bitbucket.org | |
# Run this script from the directory with all your GitHub checkouts in | |
# @TODO - Due to Mac limitations of 'find' we are listing all files, not just directories | |
# @TODO - Get a list of GitHub repos and clone them all | |
# @TODO - Do this for GitLab too | |
# Replace my_token with a token from https://github.com/settings/tokens and then uncomment this line in order to clone the first 100 of your github repositories | |
# curl 'https://api.github.com/user/repos?access_token=my_token&affiliation=owner&per_page=100' | gron | grep ssh_url | cut -d'"' -f2 | xargs -I {} git clone {} | |
# for every directory create a BitBucket repo of the same name | |
ls -1 | xargs -I {} curl -X POST -v -u username:password -H "Content-Type: application/json" \ | |
https://api.bitbucket.org/2.0/repositories/WheresAlice/{} \ | |
-d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }' | |
# For every directory add a git remote for bitbucket | |
ls -1 | xargs -I {} sh -c 'cd {} && git remote add bitbucket git@bitbucket.org:WheresAlice/{}.git' | |
# For every directory push all branches to the new bitbucket remote | |
ls -1 | xargs -I {} sh -c 'cd {} && git push --all bitbucket -u' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment