111111
111111

Reputation: 16148

Splitting out a sub directory in a git repo into it's own repo

I have the following structure:

 my_main_project/
    my_lib/
       file1
       dir2/
           file2
    my_other_files

And now, the my_lib has got to the point where it really should be it's own library, and should be a submodule in my_main_project

IE:

my_main_project/  (is repo)
    <my_lib>  (is sub module)
    my_other_files/

my_lib/ (is repo)
    file1
    dir2/
    file2

I ideally wish to keep the git history for my_lib for obvious reasons.

Anyway, I tried the following: Convert a git folder to a submodule retrospectively?

However, it fielded this error

$ git filter-branch --subdirectory-filter '../my_main_project/my_lib' --prune-empty -- --all
> fatal '../my_main_project/my_lib' is outside repository

What, am I doing wrong and what needs to be done to get this working. I should point out that my_main_project is on branch master, and that is the branch of the subdir I wish to port.

Please let me know if there is an supplementary information you need.

Upvotes: 0

Views: 631

Answers (1)

prajmus
prajmus

Reputation: 3271

The path/to/your/submodule from the post you linked to is the path to the submodule directory in your cloned repository (the new one in which you should be when executing this command) not in the original one. Judging by what you wrote it should be just my_lib

$ git filter-branch --subdirectory-filter 'my_lib' --prune-empty -- --all

Upvotes: 2

Related Questions