codefx
codefx

Reputation: 10512

How to use git filter-branch without changing project root?

I have git repo. I want to split a sub directory of the repo into its own separate repo. So, I am using https://help.github.com/en/articles/splitting-a-subfolder-out-into-a-new-repository

But the problem is this command changes the project root to the subdirectory. Is there a way I can keep the project root unchanged?

I have tried https://stackoverflow.com/a/9523876/244009 option. This just moves the whole repo one directory deeper.

Upvotes: 0

Views: 115

Answers (1)

jthill
jthill

Reputation: 60443

git filter-branch --index-filter '
                git read-tree --empty
                git read-tree --prefix=sub/tree/ $GIT_COMMIT:sub/tree/
        ' -- yourbranch -- sub/tree

should do it.

Upvotes: 2

Related Questions