Saturday, May 24, 2014

Git: Detach subdirectory into a separate git repository.
  1. Prepare the old repo
    git subtree split -P  -b 
    Note: must NOT contain leading or trailing characters btoa != ./btoa/
  2. Create the new repo
    git init
    git pull 

  • Link the new repo to Github or wherever
    git remote add origin 
    git push origin -u master
  • Cleanup, if desired
    popd # get out of 
    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.
  • ...


    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
    ├── ArrayBuffer
    ├── Audio
    ├── Blob
    ├── FormData
    ├── atob
    ├── btoa
    ├── location
    └── navigator
    I want to split out a single folder, btoa, into a separate git repository
    pushd ~/Code/node-browser-compat/
    git subtree split -P btoa -b btoa-only
    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 push origin -u master
    Happy day!
    Note: If you created a repo with a, .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 repo

    git rm -rf btoa

    also handy for when you type in the wrong origin
    git remote set-url origin

    No comments: