Does it make a difference to use the GitHub app when integrating Xcode with GitHub? - xcode

My team is using GitHub with Xcode. We use the GitHub application for OS X to commit, branch and sync. The problem is that when two or more developers add files to the project, conflicts occur in the 'project.pbxproj' file. Recently I realized there is a commit/push/pull option in Xcode.
If I stop using the GitHub application and use Xcode's commit, push, pull and merge, would those conflicts in 'project.pbxproj' file stop occurring?

You can still have conflicts.
If somebody makes a change to the project file and you make a change to the project file and you try to commit it at the same time as (or soon after) the other person, there's a good chance you'll see conflicts.
Thankfully, the "project.pbxproj" project file is text which can you can open with your favorite editor (vi or emacs or whatever) and you can resolve the conflicts rather easily.

Related

XCode not showing files pulled from Source Control

I am working on a Swift based XCode project that is synced with Git based master repository. One of my team member has added few files, to the master which I have pulled.
I find those files in my project directory, but not in my project. When I am manually trying to add these files to the project, in that case, I am getting Modify tag on my project, then I am unable to pull new changes from master.
This is very annoying. How do I take care of this.
Also, how do we make sure as a team that everyone of us is working separately on different module, and make surely everyone is able to commit/pull each other's changes.
The project folder with M tag is prohibiting us from doing so.
Edit 1
I have followed steps for this as well
git rm -r --cached ProjectName.xcodeproj
git commit -m "Removed file that shouldn't be tracked"
Even after doing this,
I had made changes in File1.swift, with my team member's changes in File2.swift
He had already committed it, I wanted to pull those changes, however due to changes in File1.swift I was unable to pull it.In order to make it work, I had to discard changes in File1.swift and then only I was able to pull those changes. If this is so, then it is defeating the purpose of using git
Xcode project files
The Xcode project file, or to be more precise, the pbxproj file inside the xcodeproj container keeps track of all files (among other things). Unlike Eclipse, Xcode does not monitor your source/project folder for changes thus does not update the list of files which can lead to inconsistencies after a merge.
Merge conflicts
If your team member adds or removes a file in his local copy of the repository and pushes his changes to the server, he basically overwrittes the pbxproj and therefore updates the list of files of the Xcode project. If you pull those changes there are two possible scenarios:
Git can merge the changes automatically which usually means it will keep your copy of the pbxproj file without the updated file references.
Git cannot merge the changes and therefore indicates a merge conflict that you need to resolve yourself. Depending on the differences and amount of changes these merge conflicts can be pretty annoying to resolve. Sometimes it might be easier to just delete your copy of the pbxproj file, use the one from the server and reapply your local changes, e.g., add file references.
In both cases you might need to compare your pbxproj file against the one from the server and merge things by hand. And yes, your project file will be marked with an M (for modified) which is perfectly fine. Just commit your changes and you are good to go again.
One more thing: Whenever you want to pull changes from the git server you can either stash your changes (git stash) or commit them.
Avoiding merge conflicts
In case you want to avoid merge conflicts in the future, I recommend having a look at the following tools.
Cocoapods
Cocoapods can be used to modularise your project into smaller pieces by creating private Pods. The benefit of this technique: You do not have to keep track of newly added or removed files. Just run pod update and you are up and running again. There are several blog posts that describe this technique in detail, e.g., here
phoenx
At my former company we had a pretty huge codebase and ran into some trouble when using Cocoapods. Therefore, we have developed our own meta-build system called phoenx. Phoenx can generate Xcode project and workspace setups of arbitrary complexity. It uses metadata files (something like Podfiles and Podspecs) to generate the projects etc. . Build settings will be stored in xcconfig files. At the moment it does not provide any setup tool so you have to invest a bit of time to write the xcconfig and metadata files by hand. We are working on a more convenient way to use it though. If you want to give it a try you can install it via sudo gem install phoenx. Documentation is available on GitHub.
Hope that helps!

How to delete files or folders in a git repository using Xcode?

My project had several folders that accidentally got added to my GitHub repository. I could delete them (one file at a time) from the GitHub website but that is tedious for a large number of files. I tried using git on the command line but it was conflicting with the Xcode source control updates. I would just like to do it graphically in Xcode if possible.
The closest Xcode question that I could find was this one, but it was about removing source control altogether, which I don't want to do.
I struggled with this for quite some time but it turned out to be fairly easy. I am sharing my answer below.
As long as you have your project already connected to a remote GitHub repository, all you have to do is use Finder to delete the files or folders.
Then go to Source Control and choose Commit and after that Push.
This will delete the files from your GitHub repository without you having to use the command line.

Workflow for XCode & Git sharing code?

What is the best practice / process for sharing code using git between developers working on an iPhone application.
Everytime I follow the normal git-fetch, git-rebase origin/master, method from the command line I get conflicts in the .xcodeproj, .xib, and Storyboard files.
The .xib isn't so bad because its ussually easy to fix, however the .xcodeproj consistently corrupts and I haven't found an easy way to consistently fix it.
What's the best workflow to share project files and resolve conflicts with git?
Conflicts in project files are always a pain. The same thing happens in .NET development and Visual Studio. The best way to handle this is to not have too many changes to merge at once. You do this by merging in each other's changes on an integration branch. To keep branches clean, you don't merge that branch or the other person's back to yours. You rely on rerere to remember all your conflicts along the way. This is the workflow I use:
http://dymitruk.com/blog/2012/02/05/branch-per-feature/
If you really get stuck, you would likely look at what changes were done on the other side (what you're merging in), checkout your version of the project file, manually do what the other branch did to the project file, and then use that as the solution to the conflict.
The issue is that the IDE is doing it's own thing when you update your project. So sometimes, you need to manually use the IDE to simulate adding all the stuff yourself and using that file as the conflict resolution.
This is the dark side of using heavy IDEs for development.

How to use Xcode with a cloned git repository

I am new to gitHub and have been invited to work on a private project. I am familiar with XCode and would like to use it to work on the project for it's autocompletion capabilities that I am used to. My problem is I don't know how to set this up so that I can pull the git repository, edit and test in XCode and then push. I have gone through a few tutorials on setting up git in XCode and I am successful in being able to connect to a repository I have pulled, but don't know how to use this as an XCode project once I have done so.
Here are a few specifics:
I made an SSH key for my computer and have cloned the repository through the terminal. Obviously I can update the files here and then use git commit and git push, however I want to use XCode for editing for code completion.
This project has a make file, though I don't know how to use these other than just typing "make all" in the terminal. I am assuming that I can set this up with Xcode so that when I build it uses the make file, but reading the documentation on this made me realize I don't understand enough to set this up.
I have tried making an Xcode project and then importing my files, but the problem is that Xcode insists on making a directory inside the project folder with the same name as the project where it stores all of the files. Therefore all of the addresses for my header files become wrong.
I assume that cloning a git project and then editing in Xcode is pretty standard. Does anyone have a place I can go for help?
Download SourceTree from the app store. It's free and kicks ass. You can just clone it in the terminal window using 'git clone WhateverOneYouWant -b WhicheverBranch'. Then just drag the project from the finder into the main sourceTree window.
Or alternatively, you can just grab it directly from gitHub on the main opening page of xcode. If there are no projects currently open, in the left part of the opening window, you'll see a line that says 'connect to a repository'.
Let me know if you have questions!
This isn't an exact answer to your question, but it does work.
If you install git separately and clone from the command line, you can:
Use Spotlight to Locate the Project folder you cloned
Double click the corresponding .xcodeproj file and start editing.

Delete an unreferenced image from repository in Xcode

I deleted default.png from my resources folder because I wanted a different image for the loading screen, but I just deleted the reference which was apparently a dumb thing to do. I dragged the new image into resources and tried to change the name to Default.png, but it won't let me, which I think is because the first Default.png is still in the repository somewhere. Anyway, how do I delete that image(and others with which I have probably done the same thing) from the repository when it is no longer visible in xcode?
What kind of repository is it? Subversion? Git?
The SCM integration in Xcode is great for checking out files and committing changes without having to leave the IDE, but it's hardly a full-blown GUI front end to either svn or git. It may be possible to fix your mistake by adding the file back to the project and then deleting it in Xcode in such a way that Xcode will remove it from the repository for you, but the simple solution is to just delete the file from the repository yourself by using the appropriate version control command. For example, if you're using Subversion you could:
svn remove default.png
to remove the file from your version of the repository. When you commit your changes, the file will be deleted in that version. (It'll still exist in previous versions -- that's the whole point of SCM, after all.)
After that, you can create the new file and add it to both the project and the repository in the usual way.
You need to manually go into your app's file structure and delete the image files themselves. Also, it is usually a good idea to "clean" the app whenever you remove files or references to files from an XCode project, since XCode can be a bit temperamental about removing files; the key combination for this is
Hope this fixes your problem.
Clean all targets should work (at least it worked for me). You can try the following:
a) delete the reference from "Copy Bundle resources" of your target
b) delete the app from Simulator/Device
c) clean all targets
Caleb is absolutely right. That fixed the problem here as well for the most files.
An easier way to get an overview of the accidentally un-deleted files, is creating a bookmark of the working copy with Versions (SVN Software - in case you use SVN). There you can detect the problematic files grafically and delete them. I always have to do this after restructuring the project folder.

Resources