Forked from iluwatar/git_deep_clone_repository.sh
Last active
August 29, 2015 14:24
-
-
Save yarick123/7346f00e1fd6db9e2bf3 to your computer and use it in GitHub Desktop.
This file contains 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
#/bin/bash -x | |
# combines only MASTER branches | |
# look at https://gofore.com/ohjelmistokehitys/merge-multiple-git-repositories-one-retaining-history/ | |
## Absolute Directories: | |
# | |
ORIG=~/tmp/_original_repos_git | |
WD=~/tmp/wd | |
DST_DIR=$WD/combined_project | |
# | |
######################## | |
rm -rf "$WD" | |
mkdir -p $WD | |
git init $DST_DIR | |
git_deep_clone_repository() { | |
REPO_URL=$1 | |
LOCAL_DIR=$2 | |
cd $WD | |
git clone $REPO_URL $LOCAL_DIR | |
cd $LOCAL_DIR | |
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do | |
git branch --track ${branch##*/} $branch | |
done | |
git remote rm origin | |
} | |
git_cleanup_repository() { | |
LOCAL_DIR=$1 | |
BIGFOLDER=$2 | |
BIGFILE=$3 | |
cd $WD/$LOCAL_DIR | |
git filter-branch --tag-name-filter cat --index-filter "git rm -r --cached --ignore-unmatch $BIGFOLDER" --prune-empty -f -- --all | |
git filter-branch --tag-name-filter cat --index-filter "git rm --cached --ignore-unmatch $BIGFILE" --prune-empty -f -- --all | |
} | |
git_rewrite_history() { | |
LOCAL_DIR=$1 | |
cd $WD/$LOCAL_DIR | |
filter='git ls-files -s | sed "s-\t\"*-&'$LOCAL_DIR'/-" | | |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ | |
git update-index --index-info && | |
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" | |
' | |
git filter-branch --index-filter \ | |
"$filter" --tag-name-filter cat -f -- --all | |
} | |
git_merge_master() { | |
LOCAL_DIR=$1 | |
cd "$WD/$LOCAL_DIR" | |
cd "$DST_DIR" | |
git remote add -f "$LOCAL_DIR" "$WD/$LOCAL_DIR" | |
git merge -m "Merge to the combined repository." "$LOCAL_DIR/master" | |
git remote rm "$LOCAL_DIR" | |
} | |
git_deep_clone_repository $ORIG/proj_A.git A | |
git_cleanup_repository nm_Branding bigfolder somefolder/bigfile.zip | |
git_rewrite_history A | |
git_merge_master A | |
git_deep_clone_repository $ORIG/proj_B.git B | |
git_cleanup_repository nm_Navigation bigfolder somefolder/bigfile.zip | |
git_rewrite_history B | |
git_merge_master B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment