After 2 evenings of failure, i’ve finally managed to create a GIT repository for the game project…
On the surface they seem very simple, Xcode will automatically create one for you when you create a new project, but (and it’s a big but), Xcode creates the type of GIT repository that is next to useless if you want to actually have multiple people coding and syncing to a single repository! What i needed was a repo sat on a network drive that acts as the central repository for my iMac and my Laptop (the 2 machines i use for development), so i can randomly develop on either machine and sync changes between them via the networked central repository.
After a lot of googling and an awful lot of trial and error, it would appear i needed to create a “bare” repository and use this as my central network repo. What complicated things even more was that my original project was created without a repo so i also had to add one to my project!
For anyone interested (and just for the record), this is what you need to do:
1. Create the “bare” central network repository: Goto Terminal and “cd” into the directory you want the repo, then type “git init –bare myproject.git”. This will create a folder called “myproject.git” which holds your bare repo.
2. Add a repo to my current Xcode project (call it the local repo): Goto Terminal and “cd” into the directory that holds the project, then type “git init”.
3. Specify which files are to be excluded from the local repo; this is REALLY important as you DON’T want Xcode user interface settings like tabs, window size, editor settings to be pushed to your repo because you’ll be pushing them forever. I often got a kind of recursive loop where i would spend 20 mins constantly committing changes that were nothing but user interface stuff!! Anyway, you just need to exclude .DS_Store and xcuserstate. To do this however you will need to edit a file called “exclude” in the info sub-folder of the projects new .git folder, trouble is, this folder is hidden. To edit open up TextEdit, goto Open file dialog and press Cmd-Shift-Dot(.) to show hidden files. Add the following to the “exclude” file:
.DS_Store
UserInterfaceState.xcuserstate
[ Note; for newer projects i think this is: UserInterface.xcuserstate, but my project required the one above ]
4. Add all project files to the local repo: back in terminal (same directory) type “git add .”
5. Commit our changes to the new local repo: in terminal again type “git commit -m “Initial Commit””.
6. Add the bare network repo you created in step 1 as a “Remote” in the local repo: In your xcode project, goto organiser and select “Repositories”, then click on “Remotes” in the local repo. Click “Add” and type in the name of your network repo (e.g. “MyProjectCentral”) and give it the network location of the myproject.git folder (you can drag and drop the folder into the dialog here and it expands to be the full path). This should now add the network “bare” repo as a remote repo in your xcode project.
7. Push your project to the “bare” network repo: Goto File Menu, “Source Control” and click “Push”. Select the “MyProjectCentral” in the drop down and push the project.
At this stage the bare network repo is now populated with your project. Any changes you now make to your local xcode project should be “Committed” and “Pushed” to your central repo when you’re ready to do so.
You can now create other working copies of this project on other machines by opening Xcode and selecting “Connect to a Repository” from the “Welcome to Xcode” screen. Just type the location of your myproject.git folder when asked and it will clone the project and create a working copy on the new machine.
And that’s it! Now, you will be able to have any number of working copies of the same project on any number of machines; and you can continue working on your project on any machine that is to hand!
Just remmember that any changes you make, ensure you “Commit” and “Push” them to the remote network repo “MyProjectCentral” when you’ve finished. It’s also a good idea to get into the habit of using “Pull” to pull any changes made by someone else (or you on another machine) from the central repo.
Phew… It took a few evenings, but it finally works beautifully…! I went down many dead ends like trying to create “Dummy branches” etc, but trust me… Don’t bother… Creating a “bare” repo is the *proper* way to do it and it works brilliantly.
Right, that’s enough for now. Hope this was of some help to someone!
Mike