Created
December 14, 2016 21:52
-
-
Save josibake/23067eafe22bb716a2b6bd174bbb25d6 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 | |
# set the env variables .. [email protected]:user/repo.git, etc | |
# Files is a small regex of all the files you want to move | |
# FILES='example.txt|/*.png' , etc | |
export OLDREPO | |
export TARGETREPO | |
export FILES | |
# clone the old repo into a old-repo directory | |
git clone $OLDREPO ~/old-repo && cd ~/old-repo | |
git checkout -b files-to-move | |
# filter the history down to just the files you are moving | |
git filter-branch -f --prune-empty --index-filter 'git ls-files | grep -v -E "$FILES" | xargs git rm --cached --ignore-unmatch' HEAD | |
# clone the target repo, add old-repo as a remote | |
# pull the files in | |
git clone $TARGETREPO ~/new-repo && cd ~/new-repo | |
git checkout -b new-files | |
git remote add here ~/old-repo/.git | |
git pull here files-to-move --allow-unrelated-histories | |
# git add . | |
# git commit -m "New files" | |
# now ready to merge into master of new repo | |
# OPTIONAL: if you want to remove the files from the old repo | |
cd ~/old-repo | |
git pull origin master --allow-unrelated-histories | |
git filter-branch -f --prune-empty --index-filter 'git ls-files | grep -E "$FILES" | xargs git rm --cached --ignore-unmatch' HEAD | |
git branch -D files-to-move |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment