Skip to content

Instantly share code, notes, and snippets.

@aseigneurin
Last active December 28, 2015 16:48
Show Gist options
  • Save aseigneurin/7531087 to your computer and use it in GitHub Desktop.
Save aseigneurin/7531087 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$#" -ne 4 ]; then
echo "Usage: $0 SOURCE_REPO SOURCE_MODULE TARGET_REPO TARGET_MODULE" >&2
echo "Example: $0 git@...:src_repo src_module git@...:target_repo target_module" >&2
exit 1
fi
SOURCE_REPO=$1
SOURCE_MODULE=$2
TARGET_REPO=$3
TARGET_MODULE=$4
mkdir $TARGET_MODULE
git clone $SOURCE_REPO $TARGET_MODULE
cd $TARGET_MODULE
for i in `git branch -a | grep -v "@" | grep $SOURCE_MODULE | sed -e "s| remotes/origin/||"`; do git branch -t $i origin/$i; done
git remote rm origin
git tag | grep "@" | xargs git tag -d
git tag | grep -v $SOURCE_MODULE | xargs git tag -d
#git filter-branch --tag-name-filter cat --prune-empty --index-filter $SOURCE_MODULE HEAD
shopt -s extglob
export TO_REMOVE=`ls -d !($SOURCE_MODULE*)`
git filter-branch --prune-empty --index-filter 'git rm -rf --cached --ignore-unmatch $TO_REMOVE' HEAD
git clean -fd
git reset --hard
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --aggressive --prune=now
git remote add origin $TARGET_REPO
#git push origin --all
#git push origin --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment