1

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.

TonyStark4ever
  • 848
  • 1
  • 9
  • 24

2 Answers2

1

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:

  1. 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.
  2. Type git init --bare, press return. A bare git repository will be created in the file you specified in the first step.
  3. 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.
  4. 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:

  1. 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".
  2. 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.
  3. 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.

TonyStark4ever
  • 848
  • 1
  • 9
  • 24
1

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.

Ali Beadle
  • 4,486
  • 3
  • 30
  • 55
  • Thanks for the tips. I was able to set it up on my router; I answered my question below. I just can't mark it as the answer for 7 more hours. I will try Working Copy. – TonyStark4ever Nov 25 '17 at 18:32