How I started using git locally on OS X

| | Comments (6)

One of the things I do is maintaining the web site of Notre Dame de Clignancourt, a church in Paris. I'm not going to give the link to the site because its design has not changed since I've started it, back in December 1999, and it's ugly hand-coded html (I did not know CSS existed at the time). But it does the work.

My work flow for this site is fairly simple: every week, I receive the newsletter from the church, which I then basically convert to html and put online. And every year I update the information about the different services that the church offer. I've never really bothered about keeping an history of the site as it corresponds to the newsletter, which I archive. And I was also thinking that since I'm now using Time Machine, it would keep the history of my local version of the site in the future.

But for some reason, maybe the warning that my Time Machine disk was getting full and old backups would be erased, this has started to bother me. So I've looked at what I could do to keep an history of the site, starting from now. I realized that this could also be a good occasion to learn git. (Why git and not subversion? As you'll see next, there was no copying to do, just a couple commands to run.) As I could not find any tutorial explaining how to do this (blame my lame google fu) and had to resort to git's manual, here is a quick post on how to do this.

First, get git. There are installers of recent versions for Leopard. I did not use their script for adding the paths, I simply created a file in /etc/paths.d and /etc/manpaths.d with the correct paths. (See man 8 path_helper on Leopard for more information.)

Second, initiate and populate the repository. I simply followed the manual, and did a

$ cd project
$ git init
$ git add .
$ git commit

Third, remove any unwanted files. (There may be a clean way to do this in step two, but I did not think about it. Maybe creating the .gitignore file before the initial add would help.) I simply did a git rm thefile for each file, and added a .gitignore file specifying the files to ignore later on.

Then any time you change files, simply tell git that you want to commit the changes: git add file_changed followed by git commit. See the relevant section of the manual for more information about this.

And this is it. Pretty simple, isn't it? The price: the size of the project has about doubled. But now I have history, without relying on Time Machine!

6 Comments

Tom said:

To remove files you don't want committed, after "add .", you can "git rm --cache files", which will remove the files from the list of files to be committed, but it won't remove them from the file system.

Alan Schmitt Author Profile Page said:

Ah, thanks a lot Tom, this will be most useful!

Didier said:

En résumé, les commandes de git sont les mêmes que cvs ou svn, sauf qu'il faut faire git add file_changed *ET* git commit
;)

J'ai essayé bazaar en ce qui me concerne. C'est bzr commit, et on ne fait add que la première fois.

Vu de loin et par un mono-utilisateur, je trouve que tous ces gestionnaires de version se valent grosso modo.

a+chaton.

Alan Schmitt Author Profile Page said:

Didier: ah non, c'est différent.

En svn, j'aurais dû:
- faire un svn import
- aller dans un autre répertoire
- faire un svn co
- et me retrouver avec deux copies sur le disque, et plein de .svn dans mes répertoires.

Avec git, la copie en plus est cachée dans le .git, et il n'y en a qu'un à la racine du projet. Ce qui est très pratique avec OS X où certains répertoires sont en fait "atomiques" (c'est mieux de ne pas s'amuser à ajouter des trucs dedans).

Didier said:

Ah oui.
ah ok ok ok ok ok

Bon, bazaar c'est pareil alors : tu fais juste

bzr init
bzr add *
bzr commit

(et pas de add à chaque fois).

Il te crée un .bzr dans le répertoire, avec l'historique.

Il paraît aussi qu'il peut merger des branches issues d'autres développeurs, il suffit d'envoyer le .bzr (par mail par exemple).

Alan Schmitt Author Profile Page said:

Je crois que si tu fais "commit -a", cela commit tout ce qui a changé. Par contre je ne sais si on peut utiliser le mail.

Mais bazar, mercurial et git, c'est tout pareil. C'est juste que j'avais plus entendu parler de git (et ça va plus vite à écrire ;-)).

Leave a comment

About this Entry

This page contains a single entry by Alan Schmitt published on May 18, 2008 9:14 PM.

Using a delay debit card with MoneyWell was the previous entry in this blog.

Data Organizers vs Data Creators is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Recently Played Games