Skip to content

Instantly share code, notes, and snippets.

@holms
Created April 20, 2018 14:10
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 holms/c42927d8a24b909992aea39d2261b342 to your computer and use it in GitHub Desktop.
Save holms/c42927d8a24b909992aea39d2261b342 to your computer and use it in GitHub Desktop.
Splitting folder to separate git repositories
# So we have this situation: repo `app` which has `serverapp` folder inside which we want to convert to separate repo
rm -rf app
rm -rf app-server
git clone git@bitbucket.org:xxxx/app.git
cp -R app app-server
cd app-server
git filter-branch --prune-empty --subdirectory-filter serverapp master
echo node_modules/ >> .gitignore # For node.js only
git add .gitignore # For node.js only
git commit -m 'Remove node_modules from git history' # For node.js only
git gc
git remote set-url origin git@bitbucket.org:xxxx/app-server.git
git push -f origin master
# So we have this situation:; repo `app` which has `serverapp` folder inside, which we want to remove from history, and current repo (what's left in it) should be pushed to new origin
rm -rf app
rm -rf app-server
git clone git@bitbucket.org:xxxx/app.git
cp -R app app-frontend
cd aml-connect-frontend
git filter-branch --tree-filter 'rm -rf serverapp' --prune-empty HEAD
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
echo serverapp/ >> .gitignore # or else it will complain about unstaged changes
git add .gitignore
git commit -m 'Remove serverapp from git history'
git gc
git remote set-url origin git@bitbucket.org:xxxx/app-frontend.git
git push origin master --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment