GIT and XCode
From Wikichris
WARNING: this is a draft, DO NOT FOLLOW this guide. It's not finished yet and not fully tested !!!
XCode proposes to create a GIT Repository when you start a new project.
We will see here how to transfer it to a remote GIT Server
Contents |
Situation
- Server : Debian 6 (Squeeze)
- GIT Server : ssh://git.company.com/var/cache/git (Install GIT as a public repository on Debian)
- Client : Mac OS 10.6.7 (Snow Leopard) + XCode 4.0.2
- Local repository : /Users/chris/Documents/my_programs/test001
Verify if you git repository is working properly
cd /Users/chris/Documents/my_programs/test001 git status
It should show the following or something equivalent
$ git status # On branch master nothing to commit (working directory clean)
Clone the repository
On the computer which runs XCode
make a clone which will be sent to the GIT Server
cd /Users/chris/Documents/my_programs git clone --bare test001 test001.git tar czf test001.tgz test001.git
On the GIT Server
Copy the previous test001.tgz into your server by your own way, then let's use it in order to copy the folder into your GIT Server
cd /var/cache/git tar xzf /home/chris/test001.tgz mv test001.git test001
If you share with HTTP, continue with
cd /var/cache/git/test001 git update-server-info cd hooks mv post-update.sample post-update
Security
Depends how you defined your security ; maybe just the following is enough if you are working alone
chown -R chris.chris /var/cache/git/test001
In my case I use ACL, so it will be more like that (I create a group and I give access to its members)
groupadd git_test001_read groupadd git_test001_write addgroup chris git_test001_write chmod -R 700 /var/cache/git/test001 setfacl -R -m g:git_test001_read:rX /var/cache/git/test001 find /var/cache/git/test001 -type d | xargs setfacl -R -m d:g:git_test001_read:rX setfacl -R -m g:git_test001_write:rwX /var/cache/git/test001 find /var/cache/git/test001 -type d | xargs setfacl -R -m d:g:git_test001_write:rwX
Back on the computer running XCode
We can now set the local repository to target a new remote server. Personally I prefer to pull an entirely new clone from the repository to be sure everything works properly. And to do so, I delete the previous local repository. Here are the 2 possibilities
SSH Configured
In order to use all the commands without having to type a login each time, the best you can do is to configure your SSH acces to work only with this command
ssh server.company.com
Even if
- the port is different than 22
- your login is different than your Macbook's
- you are using a private key
As advised by Linus Torvalds himself (creator of GIT), you should use the file ~/.ssh/config to configure the access to your server.
Host *.domaine.com port 22222 protocol 2 PubKeyAuthentication yes PasswordAuthentication no User chris
In addition to that, a Private key should be configured
- on the serveur in ~/.ssh/authorized_keys
- on your Macbook in ~/.ssh/id_dsa
Method 1: Add remote server
cd /Users/chris/Documents/my_programs/test001 git remote add origin ssh://git.company.com/var/cache/git/test001
Method 2: Pull a new repository
cd /Users/chris/Documents/my_programs/ mv test001 test001.old git clone ssh://git.company.com/var/cache/git/test001
After either of the 2 previous methods
Any futur commits will be done from XCode. Then, when you want to pull or push the result, just use these simple commands
cd ~/Documents/my_programs/test001 [...] git pull origin master [...] git push
It would be very useful to excluse all the .DS_Store file from all of your futur repositories:
git config --global core.excludesfile ~/.gitignore echo .DS_Store >> ~/.gitignore
But if you want to do it specifically for this repo, you must do it with the .git/info/exclude file
echo .DS_Store >> ~/Documents/my_programs/test001/.git/info/exclude
There's no way to do it from the server... each programmer must repeat this on all their computers.
Issues
If you have any feedback, please write to me http://offroad.gonzofamily.com/contact/
or edit this page (you just have to subscribe with a valid email).
Green/Yellow Lights
In the repositories shown in the XCode Organizer the light was yellow instead of green, but everything seemed to work correctly. It means there's an authentication problem, which is due to XCode not noticing everything is fine, connecting with a private key.
PUSH from XCode
I cannot PUSH from XCode, there's only the buttons "PULL" and "clone".
Even if I added the new repository via
XCode -> File -> Sources control -> Repositories -> <+> -> Checkout or Clone Repository
I keep launching the PUSH via the commande line
git push origin master
Command or XCode organizer ?
I tried to add the new repository via XCode interface:
XCode -> File -> Sources control -> Repositories -> <+> -> Checkout or Clone Repository
But the result is the same. No advantage that I could notice, only more questions.
With the method I wrote here, when you open your file essai.xcodeproj, the repository is automatically added anyway.