I keep encountering the same issues here, git refuses to merge based on conflicts with files existing or in use. Especially when a CocoaPods is added, and a new workspace exists where it didn’t in the initial master.
CocoaPods allow you to add modules to a project with ease. It uses features of Xcode that have existed for a while, and a LOT of libraries are available.
I wanted to shout out a solution that is easy enough, but some developers may find they are in.
Don’t annex your git repository and start over. Instead follow these few simple steps. The summary should gain your interest enough to do the steps!
A. You created a project with git, branched it, added a workspace with Pods and projects.
B. You want to merge back to master, but Xcode 5.0.1 refuses.
C. Switch to master, close – do not re-save. Then open the project not the workspace.
D. Now Merge from your branch back into master that you are in.
E. Re-open the workspace and work with new master.
Step by Step;
1. You created an Xcode project without a workspace initially with git support.
2. You add code, and eventually add a new branch to it so you can add CocoaPods module to it. Like AFNetworking. You do a new branch so it can be worked with and tested till it looks good to merge back to master. **Be sure at some point to add to git the Pods project and/or any sub projects to the source control.
At this point doing a Xcode ‘git’ merge to master fails. And switching to master and merge doesn’t work entirely as expected.
3. When you do the CocoaPods, it adds everything to a new Workspace, not the project. This is actually a good thing. If you’re new to working with workspaces, it actually helps a lot.
4. Now you have a workspace in the project. But if you try to merge your branch back to the ‘master’, it will fail because of conflicts.
5. So switch back to ‘master’ branch.
6. Xcode will ask if you should re-save, or close. CLICK CLOSE! Remember that the workspace didn’t exist in the ‘master’ source tree.
7. Reopen the project, not the workspace. This is because that is the original state of the project, no workspace existed.
8. Consider adding a tag on your master so you can revert to a prior state. Tag’s let you mark certain check in points so you can easy move between them. Xcode doesn’t support tagging yet. So use command line. **Also remember tags have to be pushed to your repository.
9. Merge from your new branch back over master. The conflict manager will open, you can choose what to do from here.
10. Close the project, and re-open the workspace, Now master has the correct Workspace properties with all the CocoaPods.
You are now ready for working again and git is all happy with merged ‘master’ from your branch.
Push your local git to the remote if you have one!
Easy Peasy! Thanks for reading!
- Bill Thompson (eSpecialized)