Fix: Untracked Working Tree Files Overwritten by Merge Error in CocoaPods

Fix: Untracked Working Tree Files Overwritten by Merge Error in CocoaPods

Written by

in

Quick answer: Run pod repo remove master followed by pod setup to reset the corrupted CocoaPods spec repository. This removes the local master spec repo that has untracked files blocking the merge, then re-clones a clean copy.

Why this happens

This error occurs when the local CocoaPods spec repository (historically named master) has untracked .podspec files that conflict with an incoming update. When you run pod install, CocoaPods attempts to update the spec repo via git pull, but Git aborts because the merge would overwrite local files that aren’t tracked in the repository.

The untracked files typically appear after a previous pod repo update or pod install was interrupted, or when spec files were manually added or modified in the ~/.cocoapods/repos/master/ directory. The error lists dozens of podspec files (e.g., AeroGear-Push/0.7.0/AeroGear-Push.podspec, SDWebImage/3.4/SDWebImage.podspec) that Git refuses to overwrite.

Note: Since CocoaPods 1.8 (2019), the default spec source is the CDN-backed trunk repository, not the Git-based master repo. This specific error is mostly seen on older setups or when the legacy master repo is still present in your sources list.

How to fix it

1. Remove the corrupted master spec repo and re-setup (recommended)

This is the cleanest fix. It deletes the problematic local clone of the master spec repository and re-initializes it from scratch.

pod repo remove master
pod setup
  • pod repo remove master deletes ~/.cocoapods/repos/master/.
  • pod setup re-clones the canonical spec repository (or configures the CDN source on modern CocoaPods).

After these commands, run pod install again in your project directory.

2. Manually delete the spec repo directory

If the pod repo command fails, remove the directory directly:

rm -rf ~/.cocoapods/repos/master
pod setup

This achieves the same result as step 1 but bypasses the CocoaPods CLI.

3. Verify your Podfile sources (modern CocoaPods)

If you’re on CocoaPods 1.8+, ensure your Podfile uses the CDN source and doesn’t reference the legacy master repo:

# Good (default since 1.8)
source 'https://cdn.cocoapods.org/'

# Legacy (causes this error if the local clone is corrupted)
# source 'https://github.com/CocoaPods/Specs.git'

Run pod repo list to see configured sources. Remove any Git-based master entry:

pod repo remove master

Then pod install will fetch specs from the CDN without a local Git repo that can get into this state.

How to prevent it

  • Keep CocoaPods updated (sudo gem install cocoapods).
  • Use the default CDN source (https://cdn.cocoapods.org/) in your Podfile; avoid the GitHub Specs repo.
  • Don’t manually edit files inside ~/.cocoapods/repos/.
  • If you must use a private spec repo, host it separately and add it via pod repo add.

FAQ

Why did rm -rf ~/.cocoapods break CocoaPods for all projects?

That command deletes the entire CocoaPods cache, including the spec repos, downloaded pods, and any local configuration. Running pod setup afterward rebuilds only the spec repo; you still need to run pod install in each project to re-download dependencies.

Does this error happen with the new CDN-based spec source?

No. The CDN source downloads spec metadata as static JSON files without a local Git repository, so there are no untracked files to block a merge. This error is specific to the legacy Git-based master spec repo.

Can I just delete the listed podspec files manually?

You could, but it’s fragile—new untracked files may appear on the next update. Removing the entire master repo and letting CocoaPods re-clone (or switching to the CDN source) is the reliable fix.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.