0

I know there are sub trees and sub modules within GIT but i am still not sure which one would be the best option in my case.

So the situation is this:

  • I have a project with "lib1" and "lib2", project and repo are already there, i am not starting from scratch
  • I want to keep all the project in the same GIT repo for easier checkin/checkout and since i mainly work on that repo
  • Project is not open source but i would like to open source "lib2"
  • I will never work on "lib2" alone, only within the main project
  • I am not expecting contributions to lib2 so merging from its repo its a minor issue
  • Ideally i'd like this to be transparent to other devs working on this project (so when they commit/push they won't need to know that there is a subtree below)

So, the idea would be to be able to push "lib2" with its own history keeping all the rest of the project private. I know there are a lot of questions on this topic already but i wasnt able to find a clear answer.

JohnUopini
  • 960
  • 9
  • 24

1 Answers1

1

You could leave the repository as it is and export this lib using:

git filter-branch --subdirectory-filer lib2

git help filer-branch says:

   --subdirectory-filter <directory>
       Only look at the history which touches the given subdirectory.
       The result will contain that directory (and only that) as its project root.

Developers of your project will not notice any change, because there is no change. - However updating that exported library would require you to run another filter-branch.

michas
  • 25,361
  • 15
  • 76
  • 121
  • This will fiter the history but how can i then push "lib2" to its own repo? Should i use subtree then? – JohnUopini Dec 18 '13 at 00:33
  • 1
    It will create a new branch containing only this directory. You can simply push that branch to another repository: `git push otherrep branch` – michas Dec 18 '13 at 00:37
  • just as a sidenode this approach works however it's kind of difficult to automatically push things to the remote repo once you change something because after filter-branch + push you have to hard reset to head to avoid issues on your main repo – JohnUopini Dec 18 '13 at 18:27