Skip to content

Instantly share code, notes, and snippets.

@bpo
Created April 7, 2014 22:45
Show Gist options
  • Select an option

  • Save bpo/10070200 to your computer and use it in GitHub Desktop.

Select an option

Save bpo/10070200 to your computer and use it in GitHub Desktop.
Add existing git repo as a subdirectory of this git repo.
# usage:
# gitaddsubdir foo https://mygit.repo
#
function gitaddsubdir () {
dirname=$1
repo=$2
git remote add -f $dirname $repo
git checkout $dirname/master -b $dirname
mkdir $dirname
# let bash globmatch hidden files
shopt -s dotglob
git mv -k ./* $dirname
echo "The above line doesn't properly handle .gitignores, so those will cause the following to break:"
echo git commit -m \"Moved this repo to a new subdirectory '$dirname'\"
echo git merge -m \"Imported $repo into $dirname\" master
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment