Git

From CUC3
Revision as of 01:05, 1 August 2008 by import>Jss43
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

git is the second project that Linus Torvalds has named after himself. It is now on the workstation image.

git is a distributed version control system (DVCS), which offer many advantages over centralised version control systems such as subversion. For git in particular:

  • Ability to use version control without the internet access required to access the wwmm server. I now have the complete history of our code on my laptop. No wifi needed! :-). It also means I can do sequential commits without needing internet access.
  • Branching and merging are *easy* and *lightweight*. This has changed how I work...
  • git-svn. Can interface (in both directions) with a subversion repository. This means that we get all the advantages of using subversion (a centralised server which is backed up and maintained by someone other than us, subversion is installed on more systems, can work with people who are using subversion and don't want to change) with none of the disadvantages (subversion makes branches an absolute pain, especially if you want to just try something out and have a play without polluting the server). The interface is so slick, that I can use git and everyone else use subversion and not know that I'm using git (but I may have just let the cat out of the bag on that one).
  • It's fast.
  • It doesn't screw around with my history or lose files.
  • It's cryptographically secure. (This isn't as bizarre as it sounds!)
  • Linus Torvalds is much smarter than us. Seriously. Oh, and he calls everyone using subversion (and cvs) stupid. Repeatedly. He managed to convince me...

It is somewhat less user friendly in places, but far more powerful, than subversion. It has wonderful graphical interfaces for viewing branches (gitk and qgit).

Things I really miss when I have to use svn:

  • stash.
  • branching and merging.
  • tab completion on the subcommands (e.g. git commit and svn commit) and a PS1 containing the branch information (see below).

Useful links

git-svn links

Cool things

Add tab completion for the git subcommands: completion script. Follow the instructions within to set up tab completion. It also contains a handy function that adds the current branch to your PS1. I added:

PS1='\u@\h:\w$(__git_ps1 " [%s]")\$ '

to my .bashrc. This only adds something when I am in a git-controlled directory. If I change directories, it remembers what branch I am in:

james@maruchon:~/work/src$ cd CPMD-NECI
james@maruchon:~/work/src/CPMD-NECI [master]$ git branch
* master
  test
james@maruchon:~/work/src/CPMD-NECI [master]$ git checkout test
Switched to branch "test"
james@maruchon:~/work/src/CPMD-NECI [test]$ cd NECI/
james@maruchon:~/work/src/CPMD-NECI/NECI [master]$ git branch
  exp
* master
james@maruchon:~/work/src/CPMD-NECI/NECI [master]$ git checkout exp
cd -Switched to branch "exp"
james@maruchon:~/work/src/CPMD-NECI/NECI [exp]$ cd -
/home/james/work/src/CPMD-NECI
james@maruchon:~/work/src/CPMD-NECI [test]$ git checkout master
Switched to branch "master"
james@maruchon:~/work/src/CPMD-NECI [master]$ cd NECI/
james@maruchon:~/work/src/CPMD-NECI/NECI [exp]$ git checkout master
Switched to branch "master"
james@maruchon:~/work/src/CPMD-NECI/NECI [master]$ cd
james@maruchon:~$ 

This is very useful (especially as git encourages branching so much!).