Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CocoaPods and GitHub forks

This is my first time forking a GitHub project, and I'm not too competent with CocoaPods either, so please bear with me.

Basically, I forked a project on GitHub using the following in my Podfile:

pod 'REActivityViewController', '~> 1.6.7', :git => 'https://github.com/<username>/REActivityViewController.git' 

I then made some changes to the fork, and of course when I did a pod install to install another pod it reinstalled the original REActivityViewController and erased my changes.

I'm realizing I need to push my changes to my fork before another pod install, but how do I know it is the fork being installed, considering that this is a repo installed by CocoaPods? I looked in the REActivityViewController folder installed under the Pods folder and there aren't any git files.

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

Or do I need to do something with submodules?

like image 687
OdieO Avatar asked Jan 05 '14 17:01

OdieO


People also ask

Can you see forks in GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Insights. In the left sidebar, click Forks.

What are GitHub forks?

A fork is a copy of a repository that you manage. Forks let you make changes to a project without affecting the original repository. You can fetch updates from or submit changes to the original repository with pull requests.

How do I link a fork to GitHub?

Creating a fork on GitHub is as easy as clicking the “fork” button on the repository page. The fork will then appear in the list of your repositories on GitHub where you can clone it to your local machine and edit it. Once you are done editing, you push your commits back to the fork on GitHub.

Can you fork a forked repository?

In this model, you fork the project repository to your own account using the GitHub website. You can then clone the forked repository to your desktop as you would any other repo. Typically you would create a working branch on the local copy of the repo, edit the documents, then push the changes to GitHub.


2 Answers

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.

like image 85
Aaron Brager Avatar answered Oct 13 '22 09:10

Aaron Brager


Another option is to have your project reference the pod directly and not via github. This way you don't have to keep committing your fork or copying/pasting code just to test your changes. You can work with two different Xcode projects simultaneously and commit separately into their respective projects.

pod 'AFNetworking', :path => '~/Documents/AFNetworking' 

CocoaPods Documentation: http://guides.cocoapods.org/using/the-podfile.html#using-the-files-from-a-folder-local-to-the-machine

enter image description here

like image 38
Oren Avatar answered Oct 13 '22 09:10

Oren