Firt of all you have to make sure you have installed git:
# apt-get install git
Make a folder where you want to store your projects, for instance: /var/GIT
Script to create a repository:
#!/bin/bash
#
# /**
# @file manage_git.sh
# @author Oscar Gomez Fuente <oscargomezf@gmail.com>
# @ingroup iThings
# @date 09/06/2016
# @version 1.0.0
# @section DESCRIPTION
# Scripts to manage repositories in svn
# */
create_git_repository() {
PATH_GIT="/var/GIT"
if [ "$#" -ne 1 ]; then
echo "[ERROR] Illegal number of parameters"
echo -e "usage: $0 [repository_name]"
echo -e "\trepository_name: name's repository"
return 1
else
if [ ! -d $PATH_GIT/$1.git ]; then
mkdir $PATH_GIT/$1.git
if [ "$?" != "0" ]; then
echo "[ERROR] Creating directory $PATH_GIT/$1.git"
return 1
fi
git init --bare --shared $PATH_GIT/$1.git
if [ "$?" != "0" ]; then
echo "[ERROR] Creating $1.git repository"
return 1
fi
chgrp -R www-data $PATH_GIT/$1.git
if [ "$?" != "0" ]; then
echo "[ERROR] Changing group to folder $PATH_GIT/$1.git"
return 1
fi
mv $PATH_GIT/$1.git/hooks/post-update.sample $PATH_GIT/$1.git/hooks/post-update
if [ "$?" != "0" ]; then
echo "[ERROR] Renaming file ../hooks/post-update.sample to ../hooks/post-update"
return 1
fi
chmod a+x $PATH_GIT/$1.git/hooks/post-update
if [ "$?" != "0" ]; then
echo "[ERROR] Changing mode to file ../hooks/pot-update"
return 1
fi
echo "[INFO] Repository $1.git created successfully"
return 0
else
echo "[ERROR] This repository name exists"
return 1
fi
fi
}
Basically you have to do the following steps:
1. Create a directory:
mkdir /var/GIT/name_project.git
2. Init the repository:
git init -bare -shared /var/GIT/name_project.git
3. Change group:
chgrp -R www-data /var/GIT/name_project.git
4. Move the following file:
mv /var/GIT/name_project.git/hooks/post-update.sample /var/GIT/name_project.git/hooks/post-update
5. Change the mode of the following file:
chmod a+x /var/GIT/name_project.git/hooks/post-update
To export a git repository that it already exists.:
1. You have to create a repository with the same name in the SERVER.
2. Copy the file ../config to ./config_new
3. Copy the file ../description to ./description_new
4. You have to copy the whole .git directory to the repository on the server:
$ scp -r ../repository_2_export/.git/* user@git.server.net:/var/GIT/name_repository.git
5. Rename the file ../config_new to ./config.
6. Rename the file ../description_new to ./description.
7. And now you can clone the repository from your local PC, to check that everything is fine:
$ git clone ssh://user@git.server.net/var/GIT/name_project.git
or:
$ git clone user@git.server.net:/var/GIT/name_project.git