Skip to content

Instantly share code, notes, and snippets.

@hlzhang
Forked from korya/Subfolder to git repo.md
Created June 30, 2020 10:28
Show Gist options
  • Save hlzhang/061a3e0037f01b78cea73dfa83ff60a8 to your computer and use it in GitHub Desktop.
Save hlzhang/061a3e0037f01b78cea73dfa83ff60a8 to your computer and use it in GitHub Desktop.

Revisions

  1. @korya korya revised this gist Feb 4, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Subfolder to git repo.md
    Original file line number Diff line number Diff line change
    @@ -21,18 +21,18 @@ $ git remote rm origin
    ### 3. Push the new repositories to the upstream server

    ```bash
    $ git remote add [email protected]:korya/submodule-repo.git
    $ git remote add origin [email protected]:korya/submodule-repo.git
    ```

    ### 4. Add the new repository as submodules to the original repository

    ```bash
    $ cd original-repo
    $ git rm sub/module/path
    $ git rm -r sub/module/path
    $ git commit -m "Removing the folders that are now repositories"
    $ git submodule add [email protected]:korya/submodule-repo.git sub/module/path
    $ git submodule init
    $ git submoduel update
    $ git submodule update
    $ git add .gitmodules sub/module/path
    $ git commit -m "Added in submodules for removed folders"
    ```
  2. @korya korya renamed this gist Feb 8, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @korya korya renamed this gist Jul 29, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @korya korya created this gist Feb 17, 2014.
    38 changes: 38 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    Source: http://willandorla.com/will/2011/01/convert-folder-into-git-submodule/


    ### 1. Clone new repository

    ```bash
    $ git clone --no-hardlinks original-repo copied-repo
    ```

    ### 2. Filter out the files you want to keep and remove the others

    ```bash
    $ cd copied-repo
    $ git filter-branch --subdirectory-filter sub/module/path HEAD -- --all
    $ git reset --hard
    $ git gc --aggressive
    $ git prune
    $ git remote rm origin
    ```

    ### 3. Push the new repositories to the upstream server

    ```bash
    $ git remote add [email protected]:korya/submodule-repo.git
    ```

    ### 4. Add the new repository as submodules to the original repository

    ```bash
    $ cd original-repo
    $ git rm sub/module/path
    $ git commit -m "Removing the folders that are now repositories"
    $ git submodule add [email protected]:korya/submodule-repo.git sub/module/path
    $ git submodule init
    $ git submoduel update
    $ git add .gitmodules sub/module/path
    $ git commit -m "Added in submodules for removed folders"
    ```