Git Local Repository Setup

#Create git user account and add to appropriate group.

sudo adduser –shell $(which git-shell) –gecos ‘git version control’ –disabled-password git
sudo usermod -a -G www-data git
sudo usermod -a -G developers git

#Setup authorized_keys file for access and fix permissions.

sudo mkdir -p /home/git/.ssh
sudo touch /home/git/.ssh/authorized_keys
sudo chmod 600 /home/git/.ssh/authorized_keys
sudo chmod 700 /home/git/.ssh

#Copy the git-shell-commands to get limited shell access and correct permission.

sudo cp -r /usr/share/doc/git/contrib/git-shell-commands /home/git/
sudo chmod 750 /home/git/git-shell-commands/*
sudo chown -R git:git /home/git/

#Create and add your SSH key to the authorized key list.

cat ~/.ssh/ | sudo tee -a /home/git/.ssh/authorized_keys
echo “AllowUsers git” | sudo tee -a /etc/ssh/sshd_config
sudo service ssh restart

#Create a location to store repositories.

sudo mkdir -p /home/repo
sudo chown -R git:www-data /home/repo

#Install gitweb and update the gitweb configuration file.

sudo apt-get install gitweb
sudo cp /etc/gitweb.conf /etc/gitweb.conf.$(date +%Y-%m-%d)
sudo sed -i ‘s/^\$projectroot.*/\$projectroot = \\”\\/home\\/repo\\”;/’ /etc/gitweb.conf
echo -e “\n\n# User additions” | sudo tee -a /etc/gitweb.conf
echo “\\$feature{‘blame’}{‘default’} = [1];” | sudo tee -a /etc/gitweb.conf
echo “\\$feature{‘search’}{‘default’} = [1];” | sudo tee -a /etc/gitweb.conf
echo “\\$feature{‘highlight’}{‘default’} = [1];” | sudo tee -a /etc/gitweb.conf
echo “\\$feature{‘grep’}{‘default’} = [1];” | sudo tee -a /etc/gitweb.conf

#Setup GitWeb executable in /home/git and use Kogakure’s gitweb-theme.

sudo mkdir /home/git/gitweb
sudo ln -s /usr/share/gitweb/gitweb.cgi /home/git/gitweb/index.cgi
git clone
sudo mv gitweb-theme /home/git/gitweb/static
sudo chown -R git:www-data /home/git/gitweb

#Edit Lighttpd configuration for localhost to include:

$HTTP[“url”] =~ “^/gitweb” {
server.document-root = “/home/git/”
server.indexfiles = (“index.cgi”)
cgi.assign = (“.cgi” => “”)

#Create a directory and initialize a bare repository.

cd /home/repo/helloworld.git
sudo git –bare init
echo “Hello World Repository. Testing system configuration” | sudo tee /home/repo/helloworld.git/description
echo “[gitweb]” | sudo tee -a /home/repo/helloworld.git/config
sudo chown -R git:www-data /home/repo/helloworld.git

sudo apt-get install lighttpd
/etc/init.d/lighttpd status
vim /etc/lighttpd/lighttpd.conf

#Clone the empty repository and add some code.

cd /home/git/gitweb/
git clone git@$(hostname):/home/repo/helloworld.git
cd helloworld

#Propose change to the working directory.

git add helloworld.cpp
git config –global “”
git config –global “your_name”

#Commit the changes made.

git commit -m “Initial commit with helloworld in C++”

#Push the changes to the remote repository.

git push origin master

Check the web interface now. The URL should be: http://localhost/gitweb and you should see the helloworld repository. To check the code-base, follow the tree link. For any new repository you want to create, follow the steps you did in “Create a directory and initialize a bare repository”.

Leave a Reply

Your email address will not be published. Required fields are marked *