deepak
deepak

Reputation: 2075

New git repo from selected files in existing repo

I have a project under git control in which the code is organized into sub-directories for different parts of the project. Now I think that the contents of a particular sub-directory might be better off being an entirely different project of their own. Is it possible to cherry-pick files (or lets just say folders) from within this project and create a new git repository with those item while retaining all their existing commit history?

I am aware of the simpler option of just copying the entire project into a new project and deleting all the files and directories that i don't want and entering that as a new commit. But I wish to know if git has something of its own for doing this.

Upvotes: 3

Views: 203

Answers (1)

VonC
VonC

Reputation: 1323303

You can use git filter-branch in order to extract a subfolder as its own repo.
See:

Once you have a new repo for that subfolder, you can reference it back in your original repo, using git submodules.

Upvotes: 1

Related Questions