:branch => 'branch-name' option to your pod declaration in the Podfile. For example: pod 'SQLite.swift', :git => 'https://github.com/stephencelis/SQLite.swift.git', :branch => 'swift3-mariotaku'. Then run pod install to fetch that branch.Why this happens
CocoaPods defaults to the default branch (usually main or master) when you specify a Git source without a branch. Many libraries maintain separate branches for different Swift versions, platform support, or experimental features. If the default branch doesn’t contain the code you need—such as a Swift 3 compatible branch for an older project—you must tell CocoaPods exactly which branch to clone.
This is common when a library hasn’t released a new version tag that includes the changes you need, or when you’re working with a fork that only exists on a feature branch.
How to fix it
1. Add the :branch option to your pod declaration
Open your Podfile and locate the pod line that points to the Git repository. Append , :branch => 'branch-name' after the :git URL. The space after the comma is required.
pod 'SQLite.swift', :git => 'https://github.com/stephencelis/SQLite.swift.git', :branch => 'swift3-mariotaku'
Replace 'swift3-mariotaku' with the actual branch name you need. You can find available branches on the repository’s GitHub page under the branch dropdown.
2. Run pod install
Save the Podfile and run:
pod install
CocoaPods will clone the specified branch instead of the default one. The Podfile.lock will record the exact commit hash from that branch, ensuring reproducible builds.
3. Verify the correct branch was fetched
Check the installed pod’s source directory:
ls -la Pods/SQLite.swift/
Or open the Pods project in Xcode and inspect the source files to confirm they match the branch you requested.
How to prevent it
- Pin to a tagged release when possible: Use
:tag => '1.2.3'instead of a branch for stable dependencies. Tags don’t move. - Document why a branch is needed: Add a comment in the Podfile explaining the reason (e.g.,
# Swift 3 compatibility branch). - Monitor the upstream repository: When the branch gets merged into a release, switch back to a versioned pod or tag to avoid drifting on an unmaintained branch.
- Use a fork with a clear branch name: If you maintain your own fork, name branches descriptively (e.g.,
fix/swift-3-support) so the intent is obvious.
FAQ
Can I use a commit hash instead of a branch?
Yes. Use :commit => 'abc1234' to lock to an exact commit. This is even more precise than a branch because branches can be force-pushed.
What if the branch name has spaces or special characters?
Wrap the branch name in quotes exactly as it appears on GitHub. Branch names with spaces work fine: :branch => 'feature/new-ui'.
Does this work with private repositories?
Yes, provided you have SSH or HTTPS access configured. Use the same syntax with a private Git URL (e.g., git@github.com:org/private-repo.git). Ensure your SSH keys or credentials are set up before running pod install.
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
