What is the best way to move a git repository with all branches and full history from bitbucket to github? Is there a script or a list of commands I have to use?
brew install jqGo to https://github.com/settings/tokens and create an access token. We only need the "repo" scope.
Save the move_me.sh script in a working folder and edit the file as needed.
Don't forget to CHMOD 755
Run! ./move_me.sh
Enjoy the time you have saved.
It will clone the BitBucket repositories inside the directory the script resides (your working directory.)
This script does not delete your BitBucket repositories.
Find and change the "private": true to "private": false below.
Checkout the developer guide, it's a couple of edits away.
Happy moving.
#!/bin/bash
BB_USERNAME=your_bitbucket_username
BB_PASSWORD=your_bitbucket_password
GH_USERNAME=your_github_username
GH_ACCESS_TOKEN=your_github_access_token
###########################
pagelen=$(curl -s -u $BB_USERNAME:$BB_PASSWORD https://api.bitbucket.org/2.0/repositories/$BB_USERNAME | jq -r '.pagelen')
echo "Total number of pages: $pagelen"
hr () {
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
}
i=1
while [ $i -le $pagelen ]
do
echo
echo "* Processing Page: $i..."
hr
pageval=$(curl -s -u $BB_USERNAME:$BB_PASSWORD https://api.bitbucket.org/2.0/repositories/$BB_USERNAME?page=$i)
next=$(echo $pageval | jq -r '.next')
slugs=($(echo $pageval | jq -r '.values[] | .slug'))
repos=($(echo $pageval | jq -r '.values[] | .links.clone[1].href'))
j=0
for repo in ${repos[@]}
do
echo "$(($j + 1)) = ${repos[$j]}"
slug=${slugs[$j]}
git clone --bare $repo
cd "$slug.git"
echo
echo "* $repo cloned, now creating $slug on github..."
echo
read -r -d '' PAYLOAD <