Skip to content

Instantly share code, notes, and snippets.

@philcali
Created March 28, 2012 19:53
Show Gist options
  • Save philcali/2229955 to your computer and use it in GitHub Desktop.
Save philcali/2229955 to your computer and use it in GitHub Desktop.
Safely removes submodules from a git repository.
#!/bin/sh
echo Removing .git directories in the submodules
cat .git/config | grep submodule | sed 's/\[submodule \"\(.*\)"\]/\1/' | xargs find | grep "./.git$" | xargs rm -r
echo Removing .git cached
cat .git/config | grep submodule | sed 's/\[submodule \"\(.*\)"\]/\1/' | xargs git rm --cached
echo Remove submodule entries from .gitmodules
git rm .gitmodules
echo Remove submodule entries from .get/config
cat .git/config | sed ':a;N;$!ba;s/\[submodule .*\]\s*//' | sed 's/^url.*//' > .git/config
# Comment out everything below if you want to verify changes
echo Adding changes
git commit -m 'Remove submodules'
# Comment out below code to NOT commit the submodule code to base repo
echo Adding previous Modules as repository code
git add .
git rm --cached rm_gitmodules
git commit -m 'Added module code'
@rrusso
Copy link

rrusso commented Mar 28, 2012

Awesome. I just copy the updated code over the second repo, ignoring the .git related files.

#!/bin/sh
###############################################################################
#Copies everything in the current folder into the folder supplied in the argument
#supersync
if [ "$1" != "" ];
    then
        echo "Syncing all files and folders from current directory to $1/"
        rsync -cazi --exclude-from=/etc/exclude.txt ./* $1
        diff -X /etc/diffexclude.txt -r ./ $1 | more
    else
        echo "Please specify the absolute path of the folder you want to copy everything into."
fi

My exclude file is as follows:

### MAC OSX Stuff ### 
- .DS_Store
- .FBCLockFolder
### svn ### 
- .svn/
### vim Open Files ### 
- *.swp
### config.php ###
- /ourmoodle/config.php
### CVS ###
- CVS/
### git ### 
- .git/
- .gitignore
- .gitmodules
### config dist file ###
- config-dist.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment