Xcode 5 using a git remote repository

Posted on Wednesday, January 8, 2014


I recently had a friend who is using Xcode and needed to set up a remote git repository for it.   I am not an Xcode user so bear with me if I miss some of the proper set up of Xcode. 

Here is the set up and instruction I used for him.




Set up a remote git Repository


I am going to set up a git server on an Ubuntu 10.04 server.  This will be for the purposes of having a Remote Repository.  I will create a user named "git" who will be the user that has the actual git repositories.  This use will not be able to login but will be able to handle git uploads via ssh (if it has shared keys from users)


Create a git user


> sudo useradd -d /home/git -s /bin/bash -m git
> sudo passwd git

Create ssh keys for git user


> su git
> ssh-keygen -t rsa -b 2048
> touch .ssh/authorized_keys



Add authorized keys for each user you want to use this git server.  In my case I was lucky enough to already have the keys I need under another user (my own)


> su patman
> cd
> sudo cp .ssh/authorized_keys /home/git/
> su git
> cd
> cat authorized_keys >> .ssh/authorized_keys






install git



> sudo apt-get install git-core



Now if you run this command


> which git


You should get






Change the shell for git


You do not want people to log in as a the git user.  To fix this you need to set the shell the git user uses to "/usr/bin/git-shell".  To do this run the following command.



> sudo chsh -s /usr/bin/git-shell git



Now if you try to log in as the git user


> su git


You get this error.




You could still log in as this use if you add the shell in the command like this


> sudo su -s /bin/bash git




Create a location to put the git repositories


Run the following commands to create a location to save Remote Repositories


> sudo mkdir -p /opt/git
> sudo chown git:git /opt/git



Now place a “bare project” in this folder for each of projects you want this server to act as a origin master for.  More information can be found here on how to do this http://git-scm.com/book/en/Git-on-the-Server-Getting-Git-on-a-Server [3]

Assuming you have a git project called my_git_project.git



> sudo su -s /bin/bash git
> cd /opt/git
> mkdir my_git_project.git
> cd my_git_project.git
> git --bare init


From my understanding the --bare init creates a shell git project for you to later push to.

This git “origin master” server should be ready to go!





Tests via command line


Before you get too far ahead of yourself you want to make sure you have access to the git server you set up.

As a test run the following command (replace example.com with your server location)


> ssh git@example.com





If you see this error "What do you think I am? A shell? You should be good to go.  This means your ssh keys are working and the git user does not allow shell access.




Git settings in Xcode 5


From Xcode from the menu select "Source Control"  then select the branch for your current open project then click Configure


 

The Configure window opens up.  
Click on remote then click the + symbol

 




Select Add Remote

 


Give it a name then in the address give it the following address (change example.com for your server)

ssh://git@example.com:22/opt/git/my_git_project.git

Then click Add Remote

 





The remote repository should be listed click done

 



To push to the remote git server from the "Source Control" menu select push.





You should see it attempt to load the remote repositories




 Once they are loaded select one and click Push





The changes begin to be pushed to the remote server







When it is done you should get a "Push Successful" notification







Quick Test


 As a quick test run this from the command line in a new folder to clone the repository from the remote git server.




> git clone ssh://git@example.com/opt/git/my_git_project.git


It should pull the code down and clone it.



Creating a new Xcode project from a cloned repository


Now that you have a project in a remote repository it's time to share it with a fellow programmer.

First you need to get their public rsa key and add it to the authorized_keys file.  Once that is done here are the steps they need to complete to get the project "cloned" from the remote repository.


Restart Xcode and click on "Check out an existing project"




Enter the git repository location

ssh://git@example.com/opt/git/my_git_project.git and click next







It will now authenticate the git server







Name the directory and click "Check Out"




The project opens and you can commit locally and push and pull from the remote server.



 


Hope this helps someone out there.


References
[1]        Git support for Visual Studio - Git, TFS, and VS put into Context     
                Accessed 04/2013
[2]        Visual Studio 2012 Update 2
                Accessed 04/2013
[3]        Visual Studio Tools for Git
                Accessed 04/2013


2 comments: