CentOS Git server and OS X Client
- January 7th, 2012
- Posted in Apple . CentOS . Coding . Development . Fedora . iOS . Linux . Objective-C . OS-X . sysadmin
- Write comment
Why?
One of the things we needed to establish for Cistec App Development was some sort of remote version control. Up until now we’d been using the world renowned Dropbox for working on our projects but it had several issues (updated in realtime, so if you attempted to compile after a colleague made a typo..).
After some googling to decide between the two version control systems Xcode will integrate with (SVN and Git) we went with Git thanks to some strong opinions on StackOverflow.
What?
We have a hosted Linux server and we access the Git repos via SSH from a potential 6+ Macs currently. We did initially have access setup via the git:// protocol but there were complications securing this so we moved to SSH.
How?
Server
You may want to have a few Git users (read-only for example) but I’ll let you sort those out yourself.
yum install git
mkdir /home/git/coolNewProject
cd /home/git/coolNewProject
git init --bare
Okay, so we’ve got the git infrastructure and a bare repo. The optional –bare means that the server doesn’t store a working copy, it just handles the source control. We found this to be easier.
Client
If you’ve got Xcode installed then you should have git already, failing that it’s available via Macports. Open the terminal and we’ll do some basic setup first:
git config --global user.name "Your Name/Handle"
git config --global user.email you@yourdomain.com
Now, an optional step is to setup SSH keys so you don’t need to enter the server’s SSH password every time you use git. Here’s a brief overview:
ssh-keygen (all defaults are fine)
cat ~/.ssh/id_rsa.pub
*copy the contents*
ssh user@server
nano/pico/vi ~/.ssh/authorized-keys (may not exist yet)
*paste it in all on one line*
Time to now pull down that nice Git repo you made, this will create a directory in your current directory so make sure you’re somewhere you want to keep your projects.
git clone user@gitserver:/home/git/coolNewProject
cd coolNewProject
When working with Xcode we have to tell Git a few things to stop it getting confused:
echo "*.pbxproj -crlf -diff -merge" > .gitattributes
nano/pico/vi .gitignore
*paste the below in*
-----------------------
# xcode noise
build/*
*.pbxuser
*.mode1v3
UserInterfaceState.xcuserstate# old skool
.svn# osx noise
.DS_Store
profile
———————–
Okay, almost ready to start using your new source control. We need do our initial add, commit and push. Copy your project into the coolNewProject directory or start a new Xcode project (without local git!).
git add .
git commit -a -m "Initial commit, repo setup."
git push master
That should be your new project files up on the server, ready for anyone else who needs to git clone them down. You can pull down any changes at any time by using ‘git pull‘. It will warn you if there are conflicts etc.
The process for committing and pushing your changes from now on is slight shorter, new files added outside of Xcode will require you to do another ‘git add .‘ but Xcode takes care of that for you if you do it within it’s GUI.
git commit -a -m "I made an awesome change to our cool new project"
git push
Xcode itself should pick up on the repo and you’ll be able to pull, commit and push via it’s source control bits (file->source control). Whilst Xcode is slower than the command line it’s conflict resolution is far superior so it’s worth using.
I find I use a combination of CLI, Xcode and SourceTree (free Git GUI, Mac app store) as they’re all good for different things.

No comments yet.