A simple BASH script to move existing git repo from Bitbucket to GitHub —
BitBucket has been fantastic over the last few years — but with pricing changes on the horizon (and GitHub pages a perfect fit for simple static sites) I have jumped ship to GitHub for 2017.
The problem is I have several hundred existing repo’s for older sites already on Bitbucket, and moving each individually would be painfully slow.
This assumes you want to use SSH to push/fetch changes from your rep. If you have not setup SSH keys already, you should, it will make committing changes much faster
The bash script is below.
Download or copy it into an existing filename.sh file.
You can make the file executable by running:
chmod +x filename.sh
If you have saved the script in your home directory you can execute it by running from the existing directory your git repo is in:
bash ~/filename.sh .
The terminating “.” will force it to run within the directory you are currently active in. The script must either be saved in the existing repo’s directory, executed from within it, or have the path of directory you want to execute it within trailing it
Remember to change the username variable to your own username.
I am using CURL and the GitHub v3 API to create a new private repo of the same name. You can change private to false if you wish it to be public.
Executing the -curl command will automatically create a new repo — it will prompt you for your password to do this. You can include the password within the -u string, however, this is never recommended (sod’s law = you leave the script/password in public repo for the world to see).