Skip to content

Instantly share code, notes, and snippets.

@smetana
Last active January 6, 2021 15:52
Show Gist options
  • Save smetana/f57b06303ddd999fbae3b42a947c754c to your computer and use it in GitHub Desktop.
Save smetana/f57b06303ddd999fbae3b42a947c754c to your computer and use it in GitHub Desktop.

Revisions

  1. smetana revised this gist Jan 6, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ git fetch tmp
    git checkout tmp/master
    git checkout -b feature/some-lib
    git rebase -i master
    git remote remove tmp
    git gc
    git prune
    ``
  2. smetana revised this gist Jan 6, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -32,13 +32,14 @@ pip3 install git-filter-repo
    ```
    ## Make fresh clone of repo1 and remove remotes
    git clone https://github.com/you/your-repo.git /home/user/repo1
    git remote remove origin
    cd /home/user/repo1
    git remote remove origin
    # Move content of the repo1 root directory to subfolder
    git filter-repo --to-subdirectory-filter lib
    # Add local modified repo1 as remote to target repo2, copy history, and rebase
    cd /home/user/repo1
    git remote add tmp /home/user/repo1
    git fetch tmp
    git checkout tmp/master
  3. smetana revised this gist Jan 6, 2021. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -38,8 +38,7 @@ cd /home/user/repo1
    # Move content of the repo1 root directory to subfolder
    git filter-repo --to-subdirectory-filter lib
    # Add local modified repo1 as remote to target repo2,
    # copy history, and rebase
    # Add local modified repo1 as remote to target repo2, copy history, and rebase
    git remote add tmp /home/user/repo1
    git fetch tmp
    git checkout tmp/master
  4. smetana revised this gist Jan 6, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@ cd /home/user/repo1
    # Move content of the repo1 root directory to subfolder
    git filter-repo --to-subdirectory-filter lib
    # Add local modified repo as remote to target repo,
    # Add local modified repo1 as remote to target repo2,
    # copy history, and rebase
    git remote add tmp /home/user/repo1
    git fetch tmp
  5. smetana revised this gist Jan 6, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ https://github.com/newren/git-filter-repo
    pip3 install git-filter-repo
    # or any other method
    ```

    ## Magic
    ```
    ## Make fresh clone of repo1 and remove remotes
    git clone https://github.com/you/your-repo.git /home/user/repo1
  6. smetana revised this gist Jan 6, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -29,8 +29,8 @@ pip3 install git-filter-repo
    # or any other method
    ```

    ## Make fresh clone of source repository and remove remote
    ```
    ## Make fresh clone of repo1 and remove remotes
    git clone https://github.com/you/your-repo.git /home/user/repo1
    git remote remove origin
    cd /home/user/repo1
  7. smetana revised this gist Jan 6, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -13,14 +13,15 @@ repo2
    We will move content and history of repo1 to lib directory of repo2

    ## After
    ```
    repo2
    |--.git
    |--.gitignore
    |-- lib
    |--.gitignore
    |--repo1_files
    |--repo2_files

    ```
    ## Tools needed
    https://github.com/newren/git-filter-repo
    ```
  8. smetana revised this gist Jan 6, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ repo2
    |--.gitignore
    |--repo2_files
    ```
    We will move content and history of repo1 to lib directory of repo1
    We will move content and history of repo1 to lib directory of repo2

    ## After
    repo2
  9. smetana revised this gist Jan 6, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ repo2
    |--.gitignore
    |--repo2_files
    ```
    ## We will move content and history of repo1 to lib directory of repo1
    We will move content and history of repo1 to lib directory of repo1

    ## After
    repo2
  10. smetana revised this gist Jan 6, 2021. 2 changed files with 50 additions and 52 deletions.
    52 changes: 0 additions & 52 deletions add_repo_as_folder_keeping_history
    Original file line number Diff line number Diff line change
    @@ -1,52 +0,0 @@
    ## Before
    ```
    repo1
    |--.git
    |--.gitignore
    |--files

    repo2
    |--.git
    |--.gitignore
    |--files
    ```

    ## After
    repo1
    |--.git
    |--.gitignore
    |-- repo2
    |--.git
    |--.gitignore
    |--files
    |--files

    ## Tools needed
    https://github.com/newren/git-filter-repo
    ```
    pip3 install git-filter-repo
    # or any other method
    ```

    ## Make fresh clone of source repository and remove its remotes
    ```
    mkdir /home/user/repo1
    cd /home/user/repo1
    git clone https://github.com/you/your-repo.git
    git remote remove origin

    # Move content of the source repo root directory to subfolder
    # (as it will be in target repo)
    git filter-repo --to-subdirectory-filter lib/some-lib

    # Add local modified repo as remote to target repo,
    # copy history, and rebase
    git remote add side-repo /home/user work
    git fetch side-repo
    git checkout side-repo/master
    git checkout -b feature/some-lib
    git rebase -i master

    git remote remove side-repo
    git gc
    ``
    50 changes: 50 additions & 0 deletions add_repo_as_folder_keeping_history.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    ## Before
    ```
    repo1
    |--.git
    |--.gitignore
    |--repo1_files
    repo2
    |--.git
    |--.gitignore
    |--repo2_files
    ```
    ## We will move content and history of repo1 to lib directory of repo1

    ## After
    repo2
    |--.git
    |--.gitignore
    |-- lib
    |--.gitignore
    |--repo1_files
    |--repo2_files

    ## Tools needed
    https://github.com/newren/git-filter-repo
    ```
    pip3 install git-filter-repo
    # or any other method
    ```

    ## Make fresh clone of source repository and remove remote
    ```
    git clone https://github.com/you/your-repo.git /home/user/repo1
    git remote remove origin
    cd /home/user/repo1
    # Move content of the repo1 root directory to subfolder
    git filter-repo --to-subdirectory-filter lib
    # Add local modified repo as remote to target repo,
    # copy history, and rebase
    git remote add tmp /home/user/repo1
    git fetch tmp
    git checkout tmp/master
    git checkout -b feature/some-lib
    git rebase -i master
    git remote remove tmp
    git gc
    ``
  11. smetana created this gist Jan 6, 2021.
    52 changes: 52 additions & 0 deletions add_repo_as_folder_keeping_history
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    ## Before
    ```
    repo1
    |--.git
    |--.gitignore
    |--files

    repo2
    |--.git
    |--.gitignore
    |--files
    ```

    ## After
    repo1
    |--.git
    |--.gitignore
    |-- repo2
    |--.git
    |--.gitignore
    |--files
    |--files

    ## Tools needed
    https://github.com/newren/git-filter-repo
    ```
    pip3 install git-filter-repo
    # or any other method
    ```

    ## Make fresh clone of source repository and remove its remotes
    ```
    mkdir /home/user/repo1
    cd /home/user/repo1
    git clone https://github.com/you/your-repo.git
    git remote remove origin

    # Move content of the source repo root directory to subfolder
    # (as it will be in target repo)
    git filter-repo --to-subdirectory-filter lib/some-lib

    # Add local modified repo as remote to target repo,
    # copy history, and rebase
    git remote add side-repo /home/user work
    git fetch side-repo
    git checkout side-repo/master
    git checkout -b feature/some-lib
    git rebase -i master

    git remote remove side-repo
    git gc
    ``