Skip to content

Instantly share code, notes, and snippets.

@jeffrade
Created October 23, 2018 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffrade/d4502f8604d8762dcea2d7c72cc8d8f3 to your computer and use it in GitHub Desktop.
Save jeffrade/d4502f8604d8762dcea2d7c72cc8d8f3 to your computer and use it in GitHub Desktop.
Bash Scripts to separate single dir to own git repo
#!/usr/bin/env bash
# To run this script, you must checkout the NEW_REPO
# repo and have it in the same dir as OLD_REPO.
#
# First execute the reset-repo.sh
# Then execute the patch-repo-start.sh
# Then execute:
# $ ./patch-repo-finish.sh
cd ../../NEW_REPO/
git add .
git commit -m "Merged conflicts"
mv FOLDER/* .
mv FOLDER/.gradle .
mv FOLDER/.gitignore .
rmdir FOLDER
git add .
git commit -S -m "Moving all project files up a level and rmdir"
git push
#!/usr/bin/env bash
# To run this script, you must checkout the NEW_REPO
# repo and have it in the same dir as the OLD_REPO.
#
# First execute the reset-repo.sh
# Then execute:
# $ ./patch-repo-start.sh
#
# Note: There might be conflicts, e.g. "empty" patch.
# So `git am` will prompt:
# Patch is empty.
# When you have resolved this problem, run "git am --continue".
# If you prefer to skip this patch, run "git am --skip" instead.
# In a separate terminal repo, go into the `NEW_REPO` dir
# and skip this with `git am --skip`
cd ../
git log --pretty=email --patch-with-stat --reverse --full-index --binary -- FOLDER > patch
cd ../NEW_REPO/
git am --committer-date-is-author-date < ../OLD_REPO/patch
#!/usr/bin/env bash
# To run this script, you must checkout the NEW_REPO
# repo and have it in the same dir as the OLD_REPO.
# Then execute:
# $ ./reset-repo.sh
cd ../../NEW_REPO/
rm -rf .git
cd ../
rm -rf NEW_REPO/* NEW_REPO/.[^.] NEW_REPO/.??*
cd NEW_REPO/
git init
git add .
git commit -S -m "Initial commit" --allow-empty
git remote add origin git@REPO_DOMAIN:ORG/NEW_REPO.git
git push -u --force origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment