When it comes to using
git within Xcode, I kind of developed a love / hate relationship. The reason for this mainly is that a lot of times it does not become clear to me as to what is happening. Here’s my latest example for this.
I like to have everything contained in one project, even stuff that is not Xcode / source code related. So, recently I did a little mockup for an already existing Xcode project (let’s call it
MyShinyProject). After saving the new file on disk as
mockup.sketch, I wanted to have it under Source Control in this project. I did drag it into Xcode, assuming that Source Control would pick up on the change.
Unfortunately, Xcode did not pick it up – I immediately saw that because the little
A next to the new file was missing in the Project Navigator. Also, when I opened up the Source Code Commit dialog, my new file
mockup.sketch was missing entirely there.
Luckily, I used to use
git on the command line, so I figured I could look up what’s going on there. I opened up a command line at the root of the project, which is the top folder that contains
MyShinyProject.xcodeproj and the subfolder
There, I was able to see the current
git-Status by issuing the following command, which produced some information:
git status .... Untracked files: (use "git add <file>..." to include in what will be committed) ProjectManager-Storyboard/mockups.sketch
So here, I could confirm that the newly added file had not been added automatically by Xcode. I figured I could change that by just adding it via the command line:
git add MyShinyProject/mockup.sketch
After having done so, the little
A right next to the file immediately appeared within the Project Navigator in Xcode. So now, with the Source Control’s Commit dialog, I was able to commit this newly added file from within Xcode and I am pretty sure that now, when the file changes again, I will be able to commit again.