A Short git "howto"

Using git is a little different than other version control systems. The simplest explanation is that you use branches in git. A lot. Always. For everything.

Did we mention the branches?

In practice, this means your normal git operation is a little more complex than CVS or SVN work flows. With CVS and SVN, you do a checkout, edit the local source tree, and then do cvs diff against the central repository to see what changed.

With git, there is no central repository. There is only your local checkout. If you edit the local checkout, then you have no idea what the differences are between the central repository and your changes. Even worse, if you pull updates from the central repository, any local changes are lost.

The solution is the following work flow:

$ git clone git://git.freeradius.org/freeradius-server.git radiusd
$ cd radiusd
$ git checkout -b local

The second line creates the branch local, and checks it out. You can then edit, commit, and do diff, pretty much like with CVS:

$ git status
	Prints out files that have changed
$ git diff files
$ git commit files

All of your changes will go to the local branch. This practice lets you track the changes between it and the master branch:

$ git diff master

You can periodically pull updates from the central repository:

$ git pull origin master:master

This command pulls the changes from the central repository and merges those changes into your local branch. Any conflicts can be fixed with a bit of work:

$ git mergetool
	You probably want kdiff3 here
$ git commit -i conflicted-files

Committing changes back to the central repository

The process of committing changes back to the central repository is more complicated than with CVS. Most of the complexity is due to the fact that the work is on a local branch, and not on the master branch. The changes have to be pushed first to the copy of the master branch, and then from there to the central repository.

Check that your local copy is up to date:

$ git pull origin master:master

Switch to the master branch, and merge the changes from your local branch:

$ git checkout master
$ git merge local

This is pretty much the only time you should commit directly to the master branch.

Check that your commits are there:

$ git log | more

And push the changes back to the central repository:

$ git push

More complex workflows are possible, of course. This document is intended to be just a short introduction for people moving from CVS.