Git Installation and Initialization:
Installation:
- Red Hat Enterprise/CentOS: Git is included with Workstation and Server installation DVD. RPM package "git" although the version is often a little behind the current release: yum install git
For the current version of Git see RHEL 6 x86_64
or RHEL 7 x86_64 RPMs (yum install git2u-all)
- Ubuntu/Debian: sudo apt-get install git
Installs packages: git-doc git-el git-arch git-cvs git-svn git-email git-daemon-run git-gui gitk gitweb
Git is a distributed CM system with user local repositories with the capability for pier to pier repository synchronization.
It is often favorable to have an "origin" server with a "master branch" to represent the release baseline.
A Git server can be configured for access via ssh or by http. Ssh requires a user system account and gives users complete unrestricted access to the repository while http access can give complete access or limited read only access.
This tutorial will outline the configuration of a Linux based Git server accessed by users via ssh.
SSH and HTTP Git server configuration
Git SSH Server:
A Git repository configured for a server will not require a working directory of checked-out code or a staging area as would a developer, thus it will only require a "bare" repository.
Users will make git pull/push requests to the server to sync code.
The server will be known as the "origin" repository.
The use of ssh to access the repository will require that each user have a system login.
For information on user accounts, see creating a new user system login.
Create Git repository:
Interface with Git repository:
- Use ssh-keygen to set up account keys
- git clone ssh://user@hostname:/srv/git/projectx/application1.git
Git User Configuration:
Git client proxy configuration:
- git --global http.proxy http://proxy.megacorp.com:80
or
- export HTTP_PROXY=proxy.megacorp.com:80
Test:
config --get http.proxy
Configure repository:
- Make everything group readable and writable: git config core.sharedrepository 1
- Make sure that merges can't happen when you push to the repo. You have to do the merges on your local machine, and then push the result:
git config receive.denyNonFastforwards true
Git client: gitk
- Red Hat: Note that Red Hat does not have a package for Gitk. The latest version is available from github.com: gitk
wget https://raw.github.com/gitster/git/master/gitk-git/gitk
chmod +x gitk
This application requires Tcl/tk.
- Mint/Ubuntu/Debian: apt-get install gitk
May also install dependency tk
Git-web Installation:
Git-web is a Perl cgi web front-end to Git which allows one to view the Git repository.
Git-web Installation:
- Red Hat/CentOS: The RPM package gitweb-caching is available from the Extra Packages for Enterprise Linux (EPEL) website and YUM repository
rpm -ivh gitweb-caching-1.6.5.2-8.b1ab8b5.el6.noarch.rpm
Installs to /var/www/gitweb-caching/...
- Mint/Ubuntu/Debian: apt-get gitweb
CGI installs to /usr/lib/cgi-bin/gitweb.cgi
Configuration:
Configure git-web by creating the file
/etc/gitweb.conf and place all changes to the configuration here. Do not edit the installation configuration.
File:
/etc/gitweb.conf
1 | $projectroot = "/srv/git/projectx/git"; |
2 | $site_name = "cm2.megacorp.com"; |
4 | $home_link_str = "GIT-Web"; |
5 | # This just makes the description field wider so you can read # it better |
6 | $projects_list_description_width = 100; |
8 | $feature{'blame'}{'default'} = [1]; |
9 | $feature{'patches'}{'default'} = [512]; |
If this is your command: git ls-remote userx@cm2.megacorp.com:/srv/git/projectx/git/master note that the "project root" is one directory higher.
Apache web server configuration file:
- Red Hat: /etc/httpd/conf.d/gitweb-caching.conf
- Mint/Ubuntu/Debian: /etc/apache2/conf.d/gitweb
Add the necessary authentication and authorization. See the YoLinux
Apache authentication and authorization tutorial
[Potential Pitfall]: If you get the error in your Apache logs:
"... File does not exist: /var/www/gitweb-caching/gitweb.js, referer:. ..."
Download the file from the Git repo: git-1.7.6.1/gitweb/static/gitweb.js
Gitweb Configuration For Multiple Git Repositories:
File:
/etc/gitweb.conf
1 | $projectroot = "/srv/git"; |
Note:
- The project root is just defined at a higher point in the directory tree. This will cover the repositories held in /srv/git/projectx/git and /srv/git/projecty/.git (for example).
- Use symbolic links to place all repositories under the same heirarchy if the repositories are scattered throughout the file system.
Trac and the Git plugin:
Trac Installation:
- Red Hat EPEL RPM downloads: https://fedoraproject.org/wiki/EPEL
Download the following RPM packages:
- trac
Requires: python-genshi06
- trac-git-plugin
Note: many of these RPM packages are listed as "x86_64" 64 bit packages but still have 32 bit "i686" dependencies.
The "i686" RPM dependencies are available on the RHEL installation DVD.
RPM package trac installs to:
/usr/bin/trac-admin
/usr/sbin/tracd
/var/www/cgi-bin/trac.cgi
/var/www/cgi-bin/trac.fcgi
/etc/trac/...
/usr/lib/python2.6/site-packages/Trac-0.12.2-py2.6.egg-info/...
/usr/lib/python2.6/site-packages/trac/...
/usr/lib/python2.6/site-packages/tracopt/...
/usr/share/doc/trac-0.12.2/...
- Mint/Ubuntu/Debian:
- apt-get install trac
This will also install the packages: libsvn1 python-genshi python-pygments python-setuptools python-subversion python-tz subversion
- apt-get install trac-git
Trac Configuration:
Trac-git integration: also see the
Trac GitPlugin wiki page
Trac configuration file:
/srv/trac/projectx/conf/trac.ini
03 | ## Best to use Trac with a "bare" and up to date repo. |
04 | repository_dir = /srv/git/projectx/git/master |
05 | ## repository_sync_per_request = (default) |
11 | cached_repository = true |
12 | persistent_cache = true |
14 | split_page_names = false |
15 | ## length revision sha-sums should be tried to be abbreviated to (must be >= 4 and <= 40); default: 7 |
17 | ## (0.12.0.3+) minimum length for which hex-strings will be interpreted as commit ids in wiki context |
21 | alt = Megacorp ProjectX |
24 | src = /images/ProjectX_logo.png |
29 | render_unsafe_content = false |
33 | tracext.git.* = enabled |
Note:
Trac Configuration For Multiple Git Repositories:
This capability is only available in Trac 0.12 and later.
Trac configuration file:
/srv/trac/projectx/conf/trac.ini
02 | repository_sync_per_request = |
07 | projectx.description=Project X |
08 | projectx.dir = /srv/git/projectx/git/master |
11 | projecty.description=Project Y |
12 | projecty.dir = /srv/git/projecty/.git |
18 | cached_repository = false |
Note:
Git post-commit hooks to update Trac:
File:
/srv/git/projectx/git/master/hooks/post-commit
2 | REV=$(git rev-parse HEAD) |
3 | trac-admin /srv/trac/projectxy changeset added projectx $REV |
File:
/srv/git/projecty/.git/hooks/post-commit
2 | REV=$(git rev-parse HEAD) |
3 | trac-admin /srv/trac/projectxy changeset added projecty $REV |
Note:
- there is a single Trac instance /srv/trac/projectxy but two Git repositories: projectx and projecty.
- These are executable scripts to be executed by Git.
Trac Admin page for defining multiple repositories:
Trac - Apache httpd web server integration:
Trac can be run using the stand-alone Trac daemon "tracd". This configuration shows the use of Apache with Trac.
File: /etc/httpd/conf.d/trac.conf
(Red Hat location)
For more on Apache authentication see:
Repository Home Page:
The final touch is to create a homepage for your repositories so that they are easy to find, especially if you are hosting multiple reporitories.
The default homepage for most major Linux distributions
(Red Hat, Fedora, CentOS, Ubuntu, Debian) is /var/www/html/index.html
Create a home page here or create a redirect to the Trac Wiki home page and post links there.
Redirect to the Trac Wiki
<META HTTP-EQUIV="Refresh" Content="0; URL=/trac/projectx">
Sample home page:
03 | < title >Welcome to Project X</ title > |
06 | < h1 >Welcome to Project X</ h1 > |
09 | < li > < a href = "/trac/projectx" >Trac Wiki</ a > </ li > |
10 | < li > < a href = "/git-caching/" >Git-web</ a > </ li > |
11 | < li > < a href = "/jenkins" >Jenkins</ a > </ li > |
Now add Continuous Build and Integration.
See the YoLinux
Jenkins tutorial.
Links:

Books: