Created
April 7, 2014 22:45
-
-
Save bpo/10070200 to your computer and use it in GitHub Desktop.
Add existing git repo as a subdirectory of this git repo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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