Install CocoaPods From GitHub Locations

In this lesson

Installing CocoaPods from different Git sources can take a bit to understand. But once you get the hang of it, it’s as simple as pointing your Podfile to a certain URL or branch/tag name.

Kyle Roberts
Swift Guru at Large

Kyle's Series


Tap on time to skip ahead


Hello world. Kyle here. And today we’re going to talk about specifying different Git things in your Podfile. In Chrome, I have the Alamofire GitHub pulled up. Look at all of those stars. Even though this is the default value, I’m just going to copy their Git link here and go back into my Podfile and add a Git tag to this. You can do that by typing :git => and then paste in that link into single quotes.


When you normally install the Alamofire Pod, it’s going to be pointing at this Git URL here because that’s the default Git URL for this library. In addition to just specifying the Git URL you can add a few things to this, such as the branch. You can type :branch => and then single quotes again.


Let’s go check out the branches. There are two branches: master, which was updated two days ago, and assets that was updated two years ago. Interesting. Let’s just specify the assets branch. That means, that if we ran a pod install on this we would be getting the Alamofire pod but from this Git URL which is the main Alamofire Git URL, but only getting the code from the assets branch. Then our code would be two years old.


We have other options. We can also check out commits, maybe there was also a commit somewhere that we wanted to be updated too. Maybe we wanted our cURL representation method to coalesce duplicate headers. That is something I’ve been dying for. We’re going to leave this Git URL the same. We’re going to change the branch tag to a commit tag and copy in the commit ID. Then, on a pod install, we’ll be downloading the Alamofire Pod from this Git URL and getting the code from that commit ID so that we will have our things coalescing duplicate headers. Man, do I hate duplicate headers.


One other fun tag is tag. The tag tag. Let’s go back up here. We can search by tags in GitHub. Most of the tags look like version releases, so I’m sure they have pod specs for these. What if we wanted the 1.0.0 tag? Now, let’s go back here and in the value for the tag tag, we’re just going to put 1.0.0. It’s probably obvious by this point but when we install the Alamofire Pod, we’ll be getting it from this Git URL and getting the code from this tag.


One other thing you may want to do is install a fork of a GitHub repo. That’s as easy as just changing the Git URL and possibly adding the commit tag to it. Let’s check out GitHub just for an example. I first looked on Alamofire, at their forks, but GitHub told me that there is too much data to process. Now, I’m on the Forks page for the AlamofireImage, which is a sub repository with image extensions to Alamofire. Let’s just click on the first fork here, three days ago by dasmer. If we wanted this fork we would be able to copy this commit as a key here and paste that into our code. The checkout is fork of this we can click Browse Files and we see that this is the fork of AlamofireImage. If we check commits the most recent one is by him, dasmer himself. We’re going to copy the Git URL here and paste that over the Alamofire URL. This would actually be better suited to AlamofireImage since this is actually an AlamofireImage fork.


It’s also possible to remove the commit tag from this fork definition. This URL is now pointing to the Git URL of that fork we were wanting. That’s great. There is a pull request out for this NSImageView extension, if you are wondering.

Additional Info

Register to get access to additional resources and info.