Skip to content

Instantly share code, notes, and snippets.

@JasonMillward
Created October 15, 2012 02:28
Show Gist options
  • Save JasonMillward/3890517 to your computer and use it in GitHub Desktop.
Save JasonMillward/3890517 to your computer and use it in GitHub Desktop.
For cloning individual repos from Bitbucket into Github. Dirty, but it works.
#!/bin/bash
#
# Stupid script for importing Bitbucket changes into Github
# Because seriously, who uses Bitbucket when you have Github?
#
#
# Define the URLs and the paths and the things
GIT_CLONE_URL=""
BIT_CLONE_URL=""
MASTER_PATH=""
WEB_DIR=""
# Get the commit ID from Bitbucket using the special API
COMMITID=$(cat $WEB_DIR/api/post.txt)
# Go to the master path
cd $MASTER_PATH
# Remove everything in the path for a fresh start
echo "Removing the repos"
rm -rf $MASTER_PATH/repos
# Create the temp repo path again
mkdir -p $MASTER_PATH/repos
# Get ready for the creation of the repos
cd $MASTER_PATH/repos/
# Clone time
echo "Cloning the repos"
git clone $BIT_CLONE_URL bitbucket --quiet
git clone $GIT_CLONE_URL github --quiet
# Clense the github repo
echo "Cleansing github"
rm -rf $MASTER_PATH/repos/github/*
# Copy all files from the Bitbucket to the Github
cp -r $MASTER_PATH/repos/bitbucket/* $MASTER_PATH/repos/github/
# Go to the github
cd $MASTER_PATH/repos/github/
# Put the statusOutput into the temp file for later
git status > /tmp/gitStatus
# Add all of the files (Just to be sure)
git add *
# Go through the status ouput file and find every file that's been deleted
# and then delete it
while read line
do
if [[ "$line" == *deleted:* ]]
then
line=${line/deleted:/}
line=${line/\#/}
git rm -r $line
fi
done < /tmp/gitStatus
# Make a commit message with the bitbucket commit ID
git commit -m "Auto sync from Bitbucket [$COMMITID]"
# Push all changes
git push
# Remove the temp file, but keep the repos,
# incase they need debugging
rm /tmp/gitStatus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment