Sunday, September 9, 2012

Creating Git repository for existing XCode projects

This problem has been puzzling me for a while...

Scenario 1:
You started a simple project just for a quick/simple test.
XCode gives you option to "Create local git repository for this project", and for some reason you didn't/forgot to tick it...


After you spent some time on it, your simple proof-of-concept project seems to worth a lot more now and you want to add it to the source control. Ooops, how do you do that again??!! You tried every possible options under "File -> Source Control" menu but none of them works, what the....$%#@!

I guess it's mainly your fault for not creating the repository at the beginning, but, but, but, wouldn't it be nice if Apple can add an option into XCode to make it easier to add existing projects to the the source control?

Scenario 2:
There's another scenario - which happens to me quite a lot - you downloaded something from the web, you "heavily" modified it (it's mine now, mine mine mine! Ha ha ha....), and again, later wants to add it to source control and..... stuck again!

Finally found a solution today, thanks to this link by Ash Furrow, I learned that you have to:

(a) create an empty repository by open a terminal, go to your project directory and run the following commands:

git init
git add .
git commit -m "Initial commit"

(b) after that, follow the following steps (you may compress the whole project into a ".gz" file first if you worried about loosing anything...)


  1. Move your existing project folder to your desktop.
  2. Make a new, empty project in Xcode with the same name as your project. Make sure the box for using a .git repo is selected.
  3. Close Xcode.
  4. Copy all files from the project folder on your desktop to the new project folder Xcode created.
  5. Double-click the project file.
  6. You'll now need to add all the files to the source control since (they'll all have question marks beside them, shown right).

And you are done! Yeah, problem solved!

0 comments:

Post a Comment