Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone of Git repository excluding subdirectory

Tags:

git

merge

clone

I have a Git repository with a lot of history. I'd like to make this accessible to others, but one of the directories in it contains proprietary code that can't be distributed. Is there any way I can make a clone of the repository (with history) that excludes that directory?

Bonus: I'd also like to be able to merge changes to the 'public' code made in the old, main repository into the clone.

like image 226
th_in_gs Avatar asked Nov 14 '22 05:11

th_in_gs


1 Answers

You cannot do that unless you are willing to rewrite each commit hash. If you decide to rewrite the history of the repository to exclude that directory, you will have to coordinate with anyone that is a contributor or consumer of the repository.

You will need to filter-branch to adjust the tree. The script will need to initially make a repository that is a submodule within the repository. It will need to commit to that inner repository anytime there is a change and adjust the submodule reference in the parent, committing that at that level as well.

You can now publish the repo and no one will be able to do a git submodule operation but that's what you want.

like image 76
Adam Dymitruk Avatar answered Dec 09 '22 12:12

Adam Dymitruk