Developer


Setup a git repository on Ubuntu Linux and use it with Xcode

This tutorial describes how to setup a git repository on Ubuntu Linux, and what steps are required to use it with Xcode on your Mac. It is assumed that you start from scratch with the installation of Ubuntu. If possible, each step includes the commands needed, so copy/paste is your friend.

Install Ubuntu with git
As we decided to use Ubuntu for our git-server, we have to install it. For this artikel Ubuntu 11.10 was used. You can check the ubuntu version with lsb_release -a.

  • download ubuntu from http://www.ubuntu.com
  • install ubuntu
    during the installation you have to choose an user and a password. Choose whatever you want.
  • update ubuntu
    sudo apt-get upgrade
    (updates ubuntu with the latest packages)
  • install git
    sudo apt-get git install git
  • create a group called “git”
    sudo groupadd git
    (the user git gets its own group)
  • create an user called „git“
    sudo useradd -g git -m -s /bin/bash -c “git user” git
    (the user git is the owner of the git-repository. It is used for instance if you access the repository for via clone or push)
  • change the password for the user “git”
    sudo passwd git

install ssh on ubuntu
ssh is needed for the communication between our Mac and the Ubuntu server.

  • install ssh
    sudo apt-get install ssh

    (you can check whether ssh is running or not with sudo service ssh status, you can start it with sudo service ssh start and you can stop it with sudo service ssh stop)
  • configure ssh for the user git
    su – git
    mkdir .ssh
    chmod 700 .ssh

ssh on the Mac
These steps have to be done on your Mac. Do it with the user you use for Xcode.

  • generate public and private key
    ssh-keygen –t rsa
    (the public key and the private key are generated for ssh trusted relationship)
  • copy it to the ubuntu server
    cd ~/.ssh
    cat id_rsa.pub | ssh git@IP_of_your_ubuntu_server „cat >> ~/.ssh/authorized_keys“
    (Ubuntu trusts your Mac since now. Means, if you login via ssh from your Mac to Ubuntu, no password is needed anymore.
    Try it out via „ssh git@IP_of_your_ubuntu_server
    (<Alt><n> for ~)
    IP_of_your_ubuntu_server can be figured out via ifconfig)

Install git on the Mac
git is not shipped with OSX (Snow Leopard, Lion)
It needs to be downloaded from http://git-scm.com/ and installed manually.

Use your own git server with Xcode
Finally, after all this hard work, we can use our own git server. And the steps below describe how to use it via Xcode.
(Most probably there are other ways, but this was the first I found and it works quite well for me)

  • create a xcode project via Xcode (lets call it xcodeTest)
    check the box „Source Control: Create local git repository for this project“
  • via terminal go to the directory „xcodeTest“
    ls –la shows the following directories
    .git
    xcodeTest
    xcodeTest.xcodeproj
    xcodeTestTests
  • clone the project (your working direcotry is still xcodeTest)
    git clone –bare .git ../xcodeTest.git
  • change the working directory
    cd ..
    now you should see two directories
    – xcodeTest
    – xcodeTest.git
  • copy the whole direcotry „xcodeTest.git“ to your ubuntu server
    scp –r xcodeTest.git git@192.168.1.105:
    (don’t forget „:“ at the end
    if you check now on your ubuntu server in the home directory of git you should see a new directory called xcodeTest.git;
    this is our master repository from where we are going to clone)
  • on the Mac delete both directories „xcodeTest“ and “xcodeTest.git”
    rm –rf xcodeTest
    rm –rf xcodeTest.git
    (no panic, we are going to clone it immediately)
  • clone the project
    git clone git@192.168.1.105:xcodeTest
    Well done. Your project “xcodeTest” is back on the Mac.
    (with the above manual steps you must not configure the remote repository in Xcode, which I couldn’t figure out how to do)From now on it’s very easy to keep our repositories up-to-date with just a few click in Xcode.
  • open the project xcodeTest via xcode
    Make changes to a file (i.e. enter //Que was here! to the file „AppDelegate.m“
  • save the changes via <CMD><S>
    you should see „M“ right to the filename „AppDelegate.m“
  • commit your changes
    „File“ -> „Source Control“ -> „Commit“
    (a new window opens which marks the difference between the old and the new version)
    add a comment and press „Commit“
    (the local git repository has been updated)
  • push it to the Ubuntu Server
    „File“ -> „Source Control“ -> „Push“
    and just press again „Push“
    (Xcode might need some seconds to connect to your Ubuntu repository and VOILÁ, your repo is up-to-date)

Well done, and don’t forget to play Findlii! LOL

Querika


One thought on “Developer

  1. Greate post. Keep posting such kind of information on your site.
    Im really impressed by your blog.
    Thanks for sharing your thoughts about.

    Regards

Comments are closed.