Convert a Git folder to a submodule retrospectively?

前端 未结 6 1117
执念已碎
执念已碎 2020-11-28 18:49

Quite often it is the case that you\'re writing a project of some kind, and after a while it becomes clear that some component of the project is actually useful as a standal

6条回答
  •  温柔的废话
    2020-11-28 19:28

    I know this is an old thread, but the answers here squash any related commits in other branches.

    A simple way to clone and keep all those extra branches and commits:

    1 - Make sure you have this git alias

    git config --global alias.clone-branches '! git branch -a | sed -n "/\/HEAD /d; /\/master$/d; /remotes/p;" | xargs -L1 git checkout -t'
    

    2 - Clone the remote, pull all branches, change the remote, filter your directory, push

    git clone git@github.com:user/existing-repo.git new-repo
    cd new-repo
    git clone-branches
    git remote rm origin
    git remote add origin git@github.com:user/new-repo.git
    git remote -v
    git filter-branch --subdirectory-filter my_directory/ -- --all
    git push --all
    git push --tags
    

提交回复
热议问题