The git repository for an existing open source library looks something like this:
A/ B/ C/
D/ E.txt F.txt
I need to create a new repository for a new library, beginning with a copy of a subset of this code. For example, I might want my repository to contain:
A/ B/ E.txt
That is, I want the new repo to contain the A
and B
directories (with their contents) and E.txt
unchanged. The new library has no need for C
, D
or F.txt
.
I can see two ways to do this:
git clone
the existing repository, thengit rm
C
,D
andF.txt
.git init
a new repository, thengit add
the latest versions ofA
,B
andE.txt
.
The problem with the first approach is that there will be significant history in the repository for the items which have been removed. This history is irrelevant for the new library. OTOH, the second approach leads to a repository with no history at all!
Which of these approaches is preferable?
Might it be better to create my new repository that contains only the relevant files and only the history for those files? Can this be done (perhaps with git filter-branch
)? Would this indeed be better than either of the above approaches?