CocoaPods and GitHub forks

I will answer this question using an example. I have a fork of TTTAttributedLabel with some extra functionality I added here:

https://github.com/getaaron/TTTAttributedLabel

In order to use this in a Cocoapods project, I:

  1. Push my changes to my fork
  2. Configure my Podfile to get the changes & update

Once you’ve pushed your changes to your fork, get the SHA of your last commit. You can do this using git rev-parse origin/master | pbcopy or on the GitHub commits page for your project:
Screenshot of copying a commit's SHA on GitHub

Then, you can specify the specific commit on your fork in your Podfile like this:

pod 'TTTAttributedLabel', :git => 'https://github.com/getaaron/TTTAttributedLabel.git', :commit => 'd358791c7f593d6ea7d6f8c2cac2cf8fae582bc1'

After that, pod update will update this particular commit from your fork. If you want, you can also make a podspec for your fork, but I find this approach simpler and I don’t make changes frequently enough to justify a new workflow.

Do I need to work on my fork outside of my project and then use Cocoapods to install the changes? That’s way to cumbersome of a workflow.

You can do it this way, but I usually:

  1. Edit the code inside my project and make sure it works
  2. Copy the changes over to my fork, by
    • exporting a patch, or
    • copying over the entire source code file
  3. Commit & push to GitHub
  4. Update the Podfile with the new SHA
  5. Run pod update.

Or do I need to do something with submodules?

No, you don’t need to.

Leave a Comment