rawsontetley.org

Setting up git

Git is one of a new breed of distributed version control systems (others include Bazaar and Mercurial). If you’re used to centralised systems, such as svn and cvs, then they’re easy to grasp - imagine that instead of commiting changes to one master server, everyone has their own server that they commit to. These local servers then send and receive patchsets through another git server, which everyone synchronises with.

Actually getting setup with git is really straightforward - install the git package from your distribution.

Whilst git has it’s own protocol, it’s much better to leave that to a better tool (the UNIX philosophy at work), so we can tell git to use ssh for communication.

The simplest setup scenario is to have a machine running git that you nominate as the server. It’s this machine that holds the latest version of code and where all the clients will send their patches.

Set it up like so:

ssh yourserver
mkdir /git/location/app.git
cd /git/location/app.git
git --bare init

That’s it - you now have an empty git repository, ready for patches to be pushed to.

On your client machine, go to your working directory, add the branch and push it up to the server (the last line allows you to issue git push and git pull without having to specify origin master every time).

cd ~/workspace/app
git init
git remote add origin ssh://yourserver/git/location/app.git
git add -A
git commit -m "Initial commit"
git push origin master
git config branch.master.remote origin && git config branch.master.merge refs/heads/master

That’s it! You’ve created your branch, pushed the content and you can continue to work. You commit changes as with any other VCS, and when you’re ready, issue a push to send your commits to the main server (conversely, a pull will receive changes sent to the server by other developers).

When another developer wants to check out and start working on the code for the first time, they just need to clone the master branch from your server:

git clone ssh://yourserver/git/location/app.git