Setting up Git with Xcode 4
In order to setup your Git repository from Beanstalk to work with Xcode, first you need to create a repository in your Beanstalk account. After you have created your repository, copy the URL of your Beanstalk repository URL to the clipboard.
Once you have copied the URL, you are ready to clone the repository and to start using it in Xcode. Before setting up Xcode 4 with your Git repository, make sure you generate ssh keys and have ssh access to your Git repository.
Setting up Xcode 4
To setup your Git repository in Xcode 4, go to File → Source Control → Manage Repositories. Once there, you will see an option to Checkout or Clone a repository:
After selecting Checkout or Clone Repository... option, you will need to enter your Git repository URL:
Click next, and on next step you should see an option to setup name of the Git repository. After setting up the name, you would be able to select where you would like to clone your repository.
You might get an error when you try to clone. Though this should not be a problem, many Xcode users have reported that this operation often fails for the first time. Just click Previous and click Clone again and then select the same location for your Git repository as before and choose Replace (replace the one left by the last failed operation). Xcode will automatically create a local git repository. Now you have a local folder which looks empty but actually contains a hidden folder ‘.git’.
Before anything else, put a file named “.gitignore” in the newly created Git repository folder with the following content:
# files created by Xcode 3 or older *.pbxuser *.mode1 *.mode1v3 *.mode2v3 *.perspectivev3 *.xcclassmodel/ # files created by Xcode 4 xcuserdata/ # build products *.build/ build/ DerivedData/ # Misc .svn .DS_Store
This way you will ignore the files in each commit and push which are not needed in your Git repository.
Import project into Git repository
Now that you have cloned your Git repository and set it up, you need to add the project which you work on in Xcode to the Git repository, so you can use version control for it. Copy your project in the newly created Git folder, where you did the clone operation.
For adding files for the first time, you would need to use Terminal in Mac Os. Fire up the Terminal, go to the Git folder, and write in Terminal: git add -all.
After that, write a commit message by command: git commit -m "commit message" and to push changes do: git push -all
Now your project is setup in Xcode with Git version control. Open the project which you added to your Git repository and you should be able to use it for commiting and pushing changes.
At this time, it looks like you can only do ‘commit’ in the Organizer window and ‘push’ through the File->Source Control->Push.
For more advanced use of Git features, you would need to use Terminal.