This document describes the local resources available on the faculty’s computers to support work with the Git version control system. You can find out more about the Git system itself, for example, in the official tutorial, or in the book *Pro Git*, or its Czech translation. The following document is not a guide to Git, but rather to its use within the FI MU network environment.
Publishing your repository
Git is a distributed version control system, which means that multiple repositories for a single project can exist at any one time (for example, from multiple developers), and individual changes (commits) can be sent to or received from these repositories.
The structure of a Git repository is designed so that no special protocol is required to read it – for example, it is sufficient to publish the repository as a standard directory via the HTTP protocol
(on FI computers, this means placing it under the directorypublic_html in your home directory – see the document on user web pages).
So, for example, if I already have an existing project in the repository/home/xpepa/nejakyprojekt, I can publish a clone of it as follows:
aisa$ mkdir -p /home/xpepa/public_html/git
aisa$ cd /home/xpepa/public_html/git
aisa$ git clone --bare /home/xpepa/nejakyprojekt nejakyprojekt.git
Cloning into bare repository 'nejakyprojekt.git'...
done.
aisa$ cd nejakyprojekt.git
aisa$ cp hooks/post-update.sample hooks/post-update
aisa$ ./hooks/post-update
Note: so-called ‘bare’ repositories are always created in a directory ending with.git.
Typographical note: in the examples, parts that depend on the specific user and on the project name and other properties they choose to use are marked in italics. When applying these, amend these parts to suit your environment.
Please note that for this to work correctly, these files must be readable by the user ‘apachefi’ or others; see the user HTML pages.
At this stage, a public clone of the repository is already available, and you can inform other users of its existence, stating that it is accessible via the URLhttps://www.fi.muni.cz/~xpepa/git/nejakyprojekt.git. Another user can, for example, download your changes to their own repository using the command `git fetch` or `git pull`, or even create a clone of your repository using the following command:
nekde$ git clone https://www.fi.muni.cz/~xpepa/nejakyprojekt.git
Cloning into 'nejakyprojekt'...
done.
Access restrictions
Using the procedure described above, we have created a public clone of your repository. There is currently no link to the repository, so it will only be available to those to whom you explicitly provide the details. However, in case the URL is guessed (which is by no means unlikely), it is possible to secure the directory with authentication, for example using a username and password. As the published repository is essentially just a directory within your web tree, you can use the standard procedure for authenticated access to user web pages.
You can then access such a repository using one of the following commands.
nekde$ git clone https://www.fi.muni.cz/~xpepa/nejakyprojekt.git
Cloning into 'nejakyprojekt'...
Username for 'https://www.fi.muni.cz':
...
# u některých starších verzí gitu (1.7.x) je nutné použít způsob
# s uvedeným přihlašovacím jménem:
nekde$ git clone https://xlogin@www.fi.muni.cz/~xpepa/nejakyprojekt.git
Password:
...
Updating the public repository
If we make further changes (commits) in our working repository, these can be published by pushing them to the public repository using the command `git push`:
aisa$ cd /home/xpepa/nejakyprojekt
aisa$ vi nejakysoubor.txt # provedeme změnu
aisa$ git commit -m 'Uprava nejakeho souboru' nejakysoubor.txt
aisa$ git push /home/xpepa/public_html/git/nejakyprojekt.git # zveřejníme
...
To .../nejakyprojekt.git/
e413f46..b652329 master -> master
Gitweb: a web interface for Git repositories
A repository published via HTTP as described above is readable by various Git clients, but not by humans. If you want the repository’s contents to be human-readable, including versioning information (date of last change, list of changes, list of branches, differences between versions, the contents of a specific file in a given or latest version, etc.), you can use a tool such as Gitweb. This tool is installed on the Aisa computer; all you need to do is redirect the directory listingshttps://www.fi.muni.cz/~xpepa/git/ andhttps://www.fi.muni.cz/~xpepa/git/nejakyprojekt.git/ to Gitweb. Access for Git clients will remain unaffected, as they never use the directory listings. The repository is then accessible via the same URL to both people and software clients.
To use Gitweb, simply place a file named.htaccess (note the full stop at the start) in the directory where your public repositories are located (for example,/home/xpepa/public_html/git from the examples above) with the following content:
# obsah souboru /home/xpepa/public_html/git/.htaccess:
Options -Indexes
RewriteEngine On
RewriteRule ^$ /git/gitweb.cgi/%{REQUEST_FILENAME} [L,PT]
RedirectMatch permanent ^(/~xpepa/git/)([a-z0-9_/-]*[a-z0-9_-])\.git/$ $1?p=$2.git
You can try out the Git web interface, for example, athttps://www.fi.muni.cz/~kas/git/.
A single repository for multiple users
In centralised version control systems (CVS, Subversion), the only possible approach is to have a single central repository into which all developers commit their changes.
Git supports various approaches (some of which are described in the manual page
gitworkflows(7)). One common approach is for a project to have a single maintainer,
to whom others submit their changes from their public repositories; the maintainer then, at their discretion, merges these into their own repository and, based on them, publishes their repository as the ‘official version’ of the project.
A centralised approach is, however, also possible in Git. To use it, however, you need to have a shared directory that can be written to by all authorised users. Support for this approach on FI machines is planned for the future. The functionality and configuration of access rights will be similar to that on the faculty’s Subversion server.