Skip to content

Instantly share code, notes, and snippets.

@scari
Last active August 29, 2015 14:13
Show Gist options
  • Save scari/674092e99ca8202c8a71 to your computer and use it in GitHub Desktop.
Save scari/674092e99ca8202c8a71 to your computer and use it in GitHub Desktop.
Import existing git repo into sub directory of another git repo.
#!/bin/bash
# NOTE:
# You couldn't track original branch (which would imported under current repo) history from current repo.
if [ "$#" -ne 2 ]; then
echo "Usage: $0 prefix url"
exit 0
fi
NAME=$1
URL=$2
PREFIX=${NAME}
TEMP_BRANCH=${NAME}_branch
git remote add $NAME $URL
git fetch $NAME
git checkout -b ${TEMP_BRANCH} ${NAME}/master
git checkout master
git read-tree --prefix=${PREFIX}/ -u ${TEMP_BRANCH}
#
echo "'${NAME}/master' from '${URL}' is now under '${PREFIX}' in curreunt repo."
echo "You can commit your changes now."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment