Search code examples
iosgitgit-submodulesgit-subtree

How to modify third party code imported with git (subtree, submodules, etc)?


I have a project that needs to support iOS7. I want to use a lib (let's call it LIB) that does not support iOS7 but could be easily modified to do so. I also expect LIB will change quite often.

What will be an ideal solution:

  1. I include LIB's code into my project (tag with the last release)

  2. I modify LIB to support iOS7 (usually only one commit). I do not want to push this commit to LIB's original repository but want to save it in my projects repository.

  3. When new LIB's version is released I update it in my project and merge with changes from point 2 or just redo these changes.

  4. I do not want to have LIB's full history in my project history (as git subtree do AFAIK). Only something like "LIB changed to 1.2.42; LIB updated to support iOS7;"

I can copy LIB's code myself or maintain LIB's fork with iOS7 support but it is time consuming and not very "automagically". I have checked git submodules and git subtree but as far as I understand it is impossible to have point 2, is it?.

What is a best approach to solve this?


Solution

  • I can … maintain LIB's fork with iOS7 support

    That's the best option here, I think.

    Fork the library and use your fork in your application. When you want to use a new version of the upstream library, merge those changes into your fork and update your main application to use the new version of your forked library.

    This is certainly possible to do using Git submodules, though a dependency manager like CocoaPods might be a better option. I generally prefer to use dependency managers when I can, though I'm not an iOS developer and can't say much about CocoaPods in particular.