http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475#17864475
- Prepare the old repo
Note:pushdgit subtree split -P -b popd must NOT contain leading or trailing charactersbtoa != ./btoa/ - Create the new repo
mkdirpushd git init git pull
git remote add origin
git push origin -u master
popd # get out of
pushd
git rm -rf
Note: This leaves all the historical references in the repository.See the Appendix below if you're actually concerned about having committed a password or you need to decreasing the file size of your .git folder.Walkthrough
These are the same steps as above, but following my exact steps for my repository instead of using.Here's a project I have for implementing JavaScript browser modules in node:
tree ~/Code/node-browser-compat
node-browser-compat
├── ArrayBuffer
├── Audio
├── Blob
├── FormData
├── atob
├── btoa
├── location
└── navigator
I want to split out a single folder, btoa, into a separate git repositorypushd ~/Code/node-browser-compat/
git subtree split -P btoa -b btoa-only
popd
I now have a new branch, btoa-only, that only has commits for btoa and I want to create a new repository.mkdir ~/Code/btoa/
pushd ~/Code/btoa/
git init
git pull ~/Code/node-browser-compat btoa-only
Next I create a new repo on Github or bitbucket, or whatever and add it is the origin (btw, "origin" is just a convention, not part of the command - you could call it "remote-server" or whatever you like)git remote add origin git@github.com:node-browser-compat/btoa.git
git push origin -u master
Happy day!Note: If you created a repo with a
README.md, .gitignore and LICENSE, you will need to pull first:git pull origin -u master
git push origin -u master
Lastly, I'll want to remove the folder from the bigger repogit rm -rf btoa
also handy for when you type in the wrong origin
git remote set-url origin https://github.com/....
No comments:
Post a Comment