How to specify the CocoaPods repository branch in podfile

Viewed 5068

We can specify the CocoaPods repository by adding the below line in podfile

 source 'https://github.com/artsy/Specs.git'

This points to the master branch. Is there any way we can specify the branch that we want to consume from the Cocoapods repository?

5 Answers

Although there's no way of switching to your desired branch, there is a workaround for this problem.

Go to Users/(your_user_name)/.cocoapods/repos/ folder. You will find your cocoapods source repository listed there. You can modify the repo to incorporate your changes.

Please note that you are modifying the master branch here.

According to http://guides.cocoapods.org/syntax/podfile.html#source there's no option to do that.

After wrangling with this problem for some time I did find a way to control the branch referenced when using source 'your-repo' from the podfile (not the podspec!!). Turns out that the podfile isnt actually pointing to master, but rather the "default branch" set in the github options for the repo. So if you go to:

GitHub Repo -> Settings Tab -> Branches -> branch you want -> Update

The default branch for the repo will be updated. After that you need to wipe the local cocoapods repo (it seems to cache the previous default branch name otherwise)

rm -rf ~/.cocoapods/repos/your-repo

Probably wouldnt hurt to wipe your pods directory and cache either. Anyway, after that, your next pod install will pull from the correct branch.

The podfile guide mentions the following syntax:

To use a different branch of the repo:

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev'
                                                                         ^^^
                                                               (the space is important)
Related