Git is a distributed revision control and source code management (SCM) system with an emphasis on speed. Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005. Based on a recent survey of Eclipse IDE users.
Every Git working directory is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server.
Git is free software distributed under the terms of the GNU General Public License version 2.
Official Website git-scm.org
Install SSH Server
$ sudo apt-get install openssh-server openssh-client
Install Git
$ sudo apt-get install git-core
Configure Git server, create Git server management user
$ sudo useradd -m git $ sudo passwd git
Create Git repository storage directory:
$ sudo mkdir /home/git/repositories
Setting Git repository permissions:
$ sudo chown git:git /home/git/repositories sudo chmod 755 /home/git/repositories
Initialize global settings:
$ git config --global user.name "username" $ git config --global user.email "username@server"
Install Git Web UI
Install Apache:
$ sudo apt-get install apache2
Install Git Web UI
$ sudo apt-get install gitweb
Configuration Gitweb
The default is no css loaded, the use of static files gitweb connected to DocumentRoot directory:
$ cd /var/www/ $ sudo ln -s /usr/share/gitweb/* .
Modify the configuration
Modify the $projectroot to git repository storage directory (for example: $projectroot = /home/git/repositories
),save and refresh your browser.
If you do not find the items that you will need to $projectroot/*
. Git attributes to 755
, so that apache user has read permissions. You can only change you need to let others through web access that git.
$ sudo chmod 755 -R gitosis-admin.git
Visit: http://localhost/cgi-bin/gitweb.cgi
Modify /etc/gitweb.conf
, like following content:
# path to git projects (.git) # $projectroot = "/var/cache/git"; $projectroot = "/home/git/repositories"; # directory to use for temp files $git_temp = "/tmp"; # target of the home link on top of all pages $home_link = $my_uri || "/"; # html text to include at home page $home_text = "indextext.html"; # file with project list; by default, simply scan the projectroot dir. $projects_list = $projectroot; # stylesheet to use @stylesheets = ("/gitweb/static/gitweb.css"); # javascript code for gitweb $javascript = "/gitweb/static/gitweb.js"; # logo to use $logo = "/gitweb/static/git-logo.png"; # the 'favicon' $favicon = "/gitweb/static/git-favicon.png"; # git-diff-tree(1) options to use for generated patches #@diff_opts = ("-M"); @diff_opts = ();
Restart Apache
$ sudo service apache2 restart
Visit: http://localhost/cgi-bin/gitweb.cgi
Install Gitosis
Install the Python's setup tools:
$ sudo apt-get install python-setuptools
Install Gitosis:
$ cd /tmp $ git clone https://github.com/res0nat0r/gitosis.git $ cd gitosis $ sudo python setup.py install
Add user for Git
$ sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git
Generate native key, switch to the localhost, if there ~/.ssh/id_rsa.pub
skip this step:
$ ssh-keygen -t rsa
Upload the key to a temporary directory server:
$ scp ~/.ssh/id_rsa.pub username@server:/tmp
Initialize gitosis (On Git server):
$ sudo -H -u git gitosis-init < /tmp/id_rsa.pub
Modify the post-update privileges:
$ sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
Clone gitosis management platform on localhost:
$ git clone username@server:gitosis-admin.git $ cd gitosis-admin
By modifying the gitosis-admin user rights management gitosis, add a public secret to keydir, add users. After modification commit, push to the server to complete the repositories permissions related operations.
Examples
Goal: Add User belief and repositories teamwork to gitosis, and cooperative management administrator xuri.
- User belief add id_rsa.pub and send it to xuri
$ belief:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/belief/.ssh/id_rsa): Created directory '/home/belief/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/belief/.ssh/id_rsa. Your public key has been saved in /home/belief/.ssh/id_rsa.pub. $ belief:~$ cp /home/belief/.ssh/id_rsa.pub /tmp
- Gitosis administrator belief assign privileges to xuri
xuri:~$ cd ~/projects $ git clone [email protected]:gitosis-admin $ cd gitosis-admin $ cat gitosis.conf [gitosis] [group gitosis-admin] writable = gitosis-admin members = xuri@ubuntu ls keydir/ [email protected] cp /tmp/id_rsa.pub keydir/belief.pub nano gitosis.conf [gitosis] [group gitosis-admin] writable = gitosis-admin members = xuri@ubuntu [group teamwork] writable = teamwork members = xuri@ubuntu belief $ git add . $ git commit -am "add member belief and project teamwork" $ git push
- User xuri add Project teamwork
xuri:~$ cd ~/projects $ mkdir teamwork $ cd teamwork $ git init $ touch readme.txt $ git add readme.txt $ git commit -am 'first commit' $ git remote add origin [email protected]:teamwork.git $ git push origin master
- User belief clone teamwork and modify readme.txt
belief:~$ git clone [email protected]:teamwork.git $ cd teamwork $ ls $ date > readme.txt $ git commit -am 'add time to readme.txt' && git push
- Users xuri pull teamwork
xuri:~/projects/teamwork$ nano .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = [email protected]:teamwork.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master $ git pull