A step by step test drive of the Xcode 4 ‘s Git integration feature.
1. Make sure have ssh access to github (http://help.github.com/mac-set-up-git/), then create am empty repository for testing. Here is my test repository’s URL:
2. ‘Clone’ the repository use Xcode.
- Open the Organizer window in Xcode.
- Press on the ‘+’ button at the bottom-left corner, and select ‘Checkout or Clone Repository’.
- Paste you git repository’s URL in the Location field, then click Next.
- Type exactly the word ‘origin‘ (without quote) in Name field. Don’t use any other name before you become a advanced user.
- Click Clone, Xcode will prompt you to select a local directory (I named the local folder Xcode4Test in this example). Select wherever you want.
- Now you may see this:
- That’s OK, many people reported this operation often fails the first time. Just lick Previous and click Clone again. Select the same location and choose Replace (replace the one left by the last failed operation).
- Now, you should see this:
– Xcode automatically created a local git repository, now you have a local folder looks empty but actually contains a hidden folder ‘.git’ (just like .svn for Subversion).
3. Tell git to ignore those files such as .DS_Store file and Xcode build directory.
- So, before anything else, put a file name “.gitignore” in the newly created folder. Here’s the content of my .gitignore
# files created by Xcode 3 or older
# files created by Xcode 4
# build products
3. Now let’s put a project in the repository.
- You may create new project from Xcode, or copy-n-pasted your existing project into the newly created folder. In this example, I copied a folder named “Hello Git” into this folder.
- Once you have the files in the folder, launch Terminal, ‘cd’ to the directory and give the command ‘git add –all’. The ‘commit’ means commit changes to the local repository. To push changes to the remote repository, you type ‘git push –all’ from the command line.
4. Work with Xcode
- At this time, it looks like I can only do ‘commit’ in the Organizer window and ‘push’ through the File->Source Control->Push….