GIT on CentOS 6

GIT + gitolite installation
Prerequisites
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

GIT installation
cd /usr/src
wget https://www.kernel.org/pub/software/scm/git/git-2.2.0.tar.gz
tar zxvf git-2.2.0.tar.gz
cd git-2.2.0

make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
#SLES
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bash.bashrc

source /etc/bashrc
#SLES
source /etc/bash.bashrc

#.bash_profile
#export PATH=$PATH:/usr/local/git/bin

git --version

After this is done, you can also get Git via Git itself for updates:
cd /usr/src
git clone git://git.kernel.org/pub/scm/git/git.git
cd git

groupadd -g 54001 git
adduser -m --system -g git -d /opt/git -s /bin/bash git

ssh-keygen -t rsa
scp .ssh/id_rsa.pub root@192.168.1.84:/tmp/git-admin.pub

su - git
git clone git://github.com/sitaramc/gitolite

cd $HOME
mkdir -p bin
gitolite/install -to $HOME/bin

cd $HOME
$HOME/bin/gitolite setup -pk /tmp/git-admin.pub

Now go to your workstation and type in
git ls-remote git@server:gitolite-admin

This should return something like 
9dd8aab60bac5e54caf887a87b4f3d35c95b05e4    HEAD
9dd8aab60bac5e54caf887a87b4f3d35c95b05e4    refs/heads/master

GIT Configuration
Prevent git push –force
git config --system receive.denyNonFastForwards true
git config --system receive.denyDeletes true

cat /usr/local/git/etc/gitconfig
[receive]
       denyNonFastForwards = true
       denyDeletes = true

Administration from workstation
yum install git
mkdir /home/user/work/git
cd /home/user/work/git/
git clone git@srvgit01v:gitolite-admin
cd gitolite-admin/
vim conf/gitolite.conf

git config --global user.name "Git-Admin"
git config --global user.email "user@domain.com"

git add keydir conf
git commit -m 'added users, repos'
git push origin master

Clients access

To check the available repos, and your access to them, use the following:
ssh git@192.168.1.100 info
or
ssh git@srvgit01v.sub1.domain.com info

Clone down the repo using:
git clone git@192.168.1.100:repo
or
git clone git@srvgit01v.sub1.domain.com:repo

Mirroring gitolite servers
Gitolite: Add, Edit, or Delete Git Repository Name

Add or create repository
Add entry for new project or repository in your gitolite config (conf/gitolite.conf)
Commit and push your changes. this will create and initialize your new repo.

Rename a repository
Modify the name of repo in your gitolite config (conf/gitolite.conf)
Move or rename the actual directory (depending on where you install it, ex: /home/git/repositories) to match your changes in gitolite config.
Commit and push your changes.

Note: Obviously, this changes the remote url of your repo, so don’t forget to change your git remote url config in your project clones.

Delete a repository:
Open your gitolite config and remove the project from there. commit and push your changes.
Then delete its git directory (ex: /home/git/repositories/projectname.git)
You can also remove users/keys that are no longer used

Generate GIT 2.2 RPM
yum install -y rpm-build

mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}

mkdir -p ~/src && cd ~/src
wget https://www.kernel.org/pub/software/scm/git/git-2.2.0.tar.gz
tar -xzvf git-2.2.0.tar.gz
mv git-2.2.0.tar.gz ~/rpmbuild/SOURCES

# Locate .spec file and build rpm
# If you get any errors during build, it is usually because of dependencies. Simply
# install the dependencies with `yum install [dependency]` and run rpmbuild again.

cd ~/src/git-2.2.0 && ls | grep *.spec

rpmbuild -ba git.spec --define '_prefix /usr/local'

Find

%files -n perl-Git -f perl-files
%defattr(-,root,root)

and add
#for CentOS 6
%config(noreplace) /usr/local/git/share/perl5/vendor_perl/*

or

#for CentOS 5
%config(noreplace) /usr/local/lib/perl5/vendor_perl/5.8.8/*
%config(noreplace) /usr/local/share/man/man3/*

If error: File /usr/src/redhat/SOURCES/git-2.2.0.tar.gz: No such file or directory
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros

or
#for Centos 7
Find

%files -n perl-Git -f perl-files
%defattr(-,root,root)

and add

%config(noreplace) /usr/local/share/perl5/vendor_perl/*

Install GIT 2.2 RPM
#CentOS 5

Installation of RPMforge
RPMforge
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.x86_64.rpm
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -i rpmforge-release-0.5.3-1.el5.rf.*.rpm
yum install perl-YAML

or
wget http://pkgs.repoforge.org/perl-YAML/perl-YAML-0.72-1.el5.rf.noarch.rpm
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
yum install perl-YAML-0.72-1.el5.rf.noarch.rpm

yum install git-2.2.0-1.x86_64.rpm git-cvs-2.2.0-1.x86_64.rpm gitk-2.2.0-1.x86_64.rpm perl-Git-2.2.0-1.x86_64.rpm git-email-2.2.0-1.x86_64.rpm git-svn-2.2.0-1.x86_64.rpm git-gui-2.2.0-1.x86_64.rpm gitweb-2.2.0-1.x86_64.rpm --nogpgcheck

#CentOS 6

yum install git-2.2.0-1.el6.x86_64.rpm gitk-2.2.0-1.el6.x86_64.rpm git-cvs-2.2.0-1.el6.x86_64.rpm git-svn-2.2.0-1.el6.x86_64.rpm git-email-2.2.0-1.el6.x86_64.rpm gitweb-2.2.0-1.el6.x86_64.rpm git-gui-2.2.0-1.el6.x86_64.rpm perl-Git-2.2.0-1.el6.x86_64.rpm

#CentOS 7

yum install git-2.2.0-1.el7.centos.x86_64.rpm git-svn-2.2.0-1.el7.centos.x86_64.rpm git-cvs-2.2.0-1.el7.centos.x86_64.rpm git-email-2.2.0-1.el7.centos.x86_64.rpm git-gui-2.2.0-1.el7.centos.x86_64.rpm gitk-2.2.0-1.el7.centos.x86_64.rpm gitweb-2.2.0-1.el7.centos.x86_64.rpm perl-Git-2.2.0-1.el7.centos.x86_64.rpm git-debuginfo-2.2.0-1.el7.centos.x86_64.rpm

Delete Git branch
ssh root@srvgit01v
cd /opt/git/repositories/repo1.git

git branch -D 4.1.0.6-rel

chown -R git:git /opt/git/repositories/repo1.git

Link:
http://www.tikalk.com/devops/backing-git-repos-git-bundle/
http://gitolite.com/gitolite/mirroring/#setting-up-mirroring

Leave a comment

You must be logged in to post a comment.