How do I sync an Xcode project between two Macs locally? - xcode

I have an Xcode project on my MacBook Pro, with a git repository stored locally. I have an iMac also, and I would like the project to sync between the two computers. I understand this is possible with git and source control, but I don't understand exactly how to do it. I also have a USB flash drive connected to my router, which both machines can access. Is there a way to clone the git repository to the flash drive (making it a remote repository?), then have both machines push and pull changes to it? Also, would the flash drive need to be a bare repository? What is the specific terminal code to do this? Thanks.

I found the answer to my question by trial and error. I created the repository file on the flash drive that is plugged in to my router. On the Mac that has the project and git repository on it:
Open Terminal, and type cd. Put a space after cd. Locate the folder you want the git repository to be in (in my case, the one created on the flash drive). Drag it from the Finder window into the Terminal window. It will type out the path to the folder for you. Press return.
Type git init --bare, press return. A bare git repository will be created in the file you specified in the first step.
Type cd, put a space after it, then drag the project folder that you are creating the git repository for into the Terminal window. Don't drag the project file, such as "Test.xcodeproj". Drag the whole project folder that the file is in, such as "Test". Press Return.
Type git remote add origin //. Drag the folder with the git repository you created in steps 1 and 2 into the terminal window. Press return.
The new bare git repository should now be created and linked in your Xcode project as a remote repository. Once that's done, copy the whole project onto your other Mac. To pass information between the two computers:
In Xcode on either Mac, click "Source Control>Commit...". In the lower left corner of the commit window, check the box that says "Push to remote." Click "Commit".
On the other Mac, open Terminal. Type cd, put a space after it, then drag the project folder into the Terminal window and press return.
Type git pull, and press return.
You should now have any changes you committed to Source Control on both Macs.
As of the writing of this answer, when "Source Control>Pull..." is clicked, Xcode crashes. This would be an easier way to pull changes than using Terminal, once that bug is fixed.

As an alternative to a local flash drive or network git repository:
You could setup a remote repository on one of the internet based git servers such as Bitbucket or GitHub (both of which offer free accounts with certain restrictions). Then sync your two macs to the same remote.
This has the additional advantage of providing a third location for your code and additional access methods such as web access or iPad access from an App such as Working Copy.

Related

XCode automatically creating repository in Home folder

Every time I open a certain project in Xcode which is under git version control, Xcode adds another repository to the organiser with the name of my user account, located in my user directory.
When trying to commit changes using Xcode, this repository shows up and shows changes from all the Xcode projects I have in my user directory. If I remove the repository from the organiser, I cannot commit any changes or pull from the remote git repository (nothing happens when these menu options are selected). However if I quit Xcode and open the project again, the repository is back.
Would appreciate it if anyone has any idea what's going on here.

can dropbox synchronize only specific files in an xcode project?

I am working on an Xcode project with a few other developers. I would like to know if there is a way that I can update only specific files of an xcode project so that I'll only make changes to those classes anytime I synchronize the project in dropbox.
Short answer: No, Dropbox doesn't do that.
You should still be able to use Dropbox source control. Here's how.
Create your project using Git in Xcode. Save the project outside of your Dropbox folder.
Copy your project from the original location into Dropbox (you now have 2 copies).
Open the original project (the one outside Dropbox) in Xcode.
Open up the Organizer and go to Repositories.
Click on "Remote" section of your project.
Click the "Add Remote" button.
Fill in the location field using file:// and the directory path the one in Dropbox
Now just push and pull changes to the remote repository as needed.
Just because you can do it though... doesn't mean you should. You get a free account from ProjectLocker which includes Git repositories and bug tracking software. It is still your private data, with full permission sets for access.

Pushing Images to Git Repo from Xcode

So this problem already helped me solve another one of our issues, but I still haven't figured this one out. (This is relevant. Hold on.)
I am developing a game with one other person. Neither of us have ever used git repositories, Github (for more than reference) or any sort of version control before, and we've had some trouble getting set up.
We have our project set up in Xcode with remotes to a GitHub repo, and everything is working fine with the code. The problem is that we can't get our images (buttons, backgrounds, animations etc.) to commit to our local repo without resorting to one of two, very roundabout, methods.
Right click on our Assets group in Xcode and select Add Files to Project. I have to do this every time we add images anyway. Then, to get Xcode to realize that these are files that need to be added to the repo (at least to get the A indicator next to the files in the organizer) we have to go in and add a blank Objective-C class, then right click the images > Source Control > Add. Then delete the blank class.
Use the GitHub app to commit the project and push it from there. This isn't working because Github's .gitignore doesn't include the xcode preference files. This makes the project unable to commit from Xcode on any other machine, and even from the machine the commit was made from after a reboot. (This is the problem we figured out trying to commit images.)
So my question is: How do we share assets for the game? I figure that Xcode will do the same for sounds, we just haven't gotten there yet. Is there an easier way to get Xcode to recognize them? Or do we just need to add those user profile files to the .gitignore on GitHub? (And how do we do this?)
Every one using Git just has to watch these two videos:
Git For Ages 4 And Up
http://www.youtube.com/watch?v=1ffBJ4sVUb4
Advanced Git
http://vimeo.com/49444883
1) I've found the best way to add images to my Xcode project is to just create the directory structure I want in the Finder then just drag and drop them from my finder in to the proper group in Xcode Project Navigator. Multi select all the new files, right click (control-click on a laptop) and select Source Control -> Add
And Bobs your uncle!
2) I do not use the GitHub app, I use SourceTree and the GitHub website. I've 20 years experience with command line source control systems but Xcode and SourceTree are so good the command line is no longer a part of my daily workflow.
I create a new Xcode project and check Create local git repository for this project then I go to the GitHub create a new repository with the same name as my project's top level directory. Copy the GitHub url. Drag the new project directory into SourceTree's Bookmarks window. Double Click on the new project view in SourceTree. Right mouse click on REMOTES and paste the GitHub url and enter origin/master for the name. Click the big push toolbar button.
3) You need to add your user scheme and workspace file to .gitignore to push and pull from a remote you have to have a clean working repo. This is super simple with SourceTree just commit in Xcode and then open the project in SourceTree right click on the WorkspaceSettings.xcsettings and *.xccheme file and select Ignore... and it creates the .gitignore file for you. Now commit the .gitignore file and Push to the remote.
FYI: Check out SourceTree (http://www.sourcetreeapp.com) is's free in the Mac App Store. It's a very good GUI for Git. Atlassian makers of Jira acquired it and the original developer and released free to compliment the rest of there tools.

git(osis) and Xcode

I installed (successfully) gitosis. I want to use it at my debian (rootserver) to access my Xcode projects (and merge, etc.). I'm able to clone the git repo with Xcode successfully, but if I try to push some (committed) changes, Xcode tells me "Choose the Remote to witch to push the changes" But I can't select any. I am able to push via Terminal.app, but that's not very comfortable. So why is Xcode telling me, there are no remotes available? I tried to add the remote manually (it is something like "gitosis#myserver.com:repositories/gitosis-admin.git"), I tried with ssh://gitosis#my..., but this dosen't even work with terminal.app.
So why is Xcode telling me "No Remotes available"?
Go to the organizer, click repositories, click yours, go to remote, click add remote, should be able to add it from there. should ask for verification and such. never used gitosis but that's how it works for git.

Xcode/Git Repository Error: "Please verify that the working copy is reachable and try again."

Here are the steps I take.
I open Xcode (4.3.3) organizer and select Checkout or Clone Repository
I choose the location https://MyUsername#bitbucket.org/MyUsername/myrepo.git
Press Clone button and it successfully clones it on my local disk
So I open the local copy of the project and perform some changes to it.
When I try to commit changes (or do any other git related operation) I get the following error:
The working copy "MyAppName" could not be reached.
Please verify that the working copy is reachable and try again.
However I can perform commits (and other types of git operations) without any issues from the Terminal app using command lines.
I've tried restarting my computer, deleting all Xcode settings, but nothing helped.
Update: I tried it again today and it works fine now. Maybe it's some sort of an intermittent bug in Xcode.
Whenever this happens to me (and it happens often) I do the following:
1-Close the project
2-Open the organiser
3-Go into the repositories tab.
If your current working copy has been added to the list already, then within the organizer navigate to it, and double-click on the .xcodeproj project.
This will re-open the project in XCode, and you'll find that now SCM operation will work fine.
If your current working copy hasn't been added to the list, press the + button in the bottom left corner, select "Add Working Copy", navigate to the folder containing the .xcodeproj and open this folder.
Now double click on the .xcodeproj file, the project will open in XCode.
And it's all working fine again...
No idea why this make things work... but it does
I have the same problem. It happens if you have ~/ in the path to project. Works fine, when you open your project from organizer.
It's a bug of Xcode! When you search the xxx.xcodeproj from your Home folder of the dialog box directly, Xcode will use the ~/xxx/xxx as the SVN/Git path which is completely wrong.
So you should avoid this, and search from the "/" path instead.
This is not exactly the answer you might be looking for, but I ran across similar problems when using Remote git repository (Github) and Xcode.
I ended up using a GUI tool "SourceTree", a good and easy to use tool to pull/push your code from Local Git to Remote Git Repository. Try it out http://sourcetreeapp.com/

Resources