git - Fast Version Control System
Git is a version control system, which was originally written by Linus Torvalds in order to host the Linux kernel. Accordingly, git has been designed to handle very large projects with speed and efficiency. Meanwhile, git is also used by other large projects like Gnome, KDE, Qt, Android, PostgreSQL, and X.org. Of course, git is just as well suited for small personal repositories.
Git falls in the category of distributed source code management tools, similar to e.g. Mercurial or Bazaar. Every git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Still, git stays very space efficient. Furthermore, git is extremely fast, powerful and easy to use.
Git is an open source project covered by the GNU General Public License v2, and is currently maintained by Junio C. Hamano.
Before you can use git on SuperMUC or the Linux Cluster, you have to load the corresponding environment module:
module load git
After that, you can invoke git commands via
Installing git from source is so simple that the author of this article never checked for the availability of binary packages - until he was to write these lines.
You can obtain binary packages for all major operating systems (Linux, Mac OS, Windows) as well as the source code from git's homepage.
The following should be a reasonable starting point for your personal git configuration. In order that it applies to all your git repositories, you should put these lines into the file $HOME/.gitconfig on all hosts where you are using git:
[user] name = Reiner Zufall email = Reiner.Zufall@dubious.domain.org [color] branch = true diff = true status = true [merge] conflictstyle = diff3
Your name and email address are recorded in any newly created commit. Thus, they should not be that arbitrary and dubious. Apart from setting your name and email address, these lines enable color in the output of certain git commands and specify the style in which conflicted hunks are written out to working tree files upon merge.
Bash Command Line Completion
In order to enable bash's command line completion for git commands and subcommands, you shoud unzip this file and save it in your home directory in $HOME/.bash_completions_git.sh and add the following lines to your $HOME/.bashrc:
if [ -f ~/.bash_completions_git.sh ]; then . ~/.bash_completions_git.sh fi
Again, you should do this on all machines, where you are using git. The above file was written by Shawn O. Pearce. After downloading and unpacking the latest source tar ball from git's home page you can also find it (or rather a more recent version of it) in the directory contrib/completion/. In this file a Shell function __git_ps1() is defined, which you can use to display the currently checked out branch in your prompt. Enable this very nice feature by adding the line
PS1='\u@\h:\w$(__git_ps1 " (%s)")> '
inside the above if-statement to your $HOME/.bashrc file. The %s token will be the name of the current branch. The argument to __git_ps1 will be displayed only if you are currently in a git repository.
Cloning Repositories / Pulling Changes to SuperMUC
This section is of concern only to SuperMUC users!
SuperMUC is protected by a very restrictive firewall. As a consequence, users are only permitted to log into SuperMUC using ssh or Grid Middleware from distinguished hosts, which have to be specified in the project application. Additionally, once you are logged into SuperMUC, you are barred from directly reaching any other machine. Unfortunately, this prevents you from cloning or pulling code from external (with respect to SuperMUC) repositories to SuperMUC in a straightforward way.
An example for this is provided by git itself. The straightforward command to obtain git's source code via git itself reads
git clone git://github.com/git/git
On SuperMUC, however, this command will fail because the firewall mentioned above denies access to the external server. Here are two workarounds:
Using ssh port forwarding
In case the straightforward commands fail, first of all you should attempt to use an ssh tunnel. The following example shows how you would translate the above line to ssh port forwarding:
Log into SuperMUC with
ssh -R 12345:github.com:9418 <Your Login>@supermuc.lrz.de
This creates an ssh tunnel from SuperMUC (with TCP source port 12345) to git.kernel.org (with TCP destination port 9418). While the first port can be chosen almost arbitrarily, the second port is fixed by the repository server. E.g. 9418 is the port on which the git-daemon is listening and which is used for the git protocol.
Now, you can clone the repository with
git clone git://localhost:12345/git/git
Please take care that you use a tunnel entrance port that is not already used by another user. So, instead of 12345 you should choose an arbitrary number between 10000 and 65535.
Using sshfs on your local machine
If for some reason port forwarding does not work, you have the possibility to use sshfs. sshfs allows you to access files on a remote machine through a local directory just as if the files were found on your local machine.
You have to make sure that you are using at least git version 220.127.116.11 on your local machine, or any later release.
sshfs -o workaround=rename <Your Login>@supermuc.lrz.de: <Mount Point>
to mount your home directory on SuperMUC to some mount point on your local machine. Note the workaround option, it is essential!
On your local machine you can then execute the commands
cd <Mount Point>/Some/Directorygit clone /Path/To/Your/Repository
Of course, in this way you can also pull or fetch changes from the repository on your local machine.
git's home page offers plenty of useful links to documentation. Some of these links are given explicitely in the following.
As git's man page is available in the web, we abstained from installing the man pages on our machines.
Newbies can find a nice elementary introduction in the git tutorial. In particular, you learn how to start your git configuration and how you initialize your first git repository. Very easy!
Next, Everyday Git tells you, how you can use git properly in various specific situations, e.g. when you are a standalone developer or when participating in a project together with a couple of other developers.
Subversion users might want to read the SVN Crash Course.
Finally, there is also the complete user manual.