Git Server on Ubuntu

Taking care of your Linux box.
Post Reply
mejam
Havaldaar
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
Location: Lahore
Contact:

Git Server on Ubuntu

Post by mejam »

This is a simple how-to which describes an easy installation of GIT.

=============================================
#Installing GIT

apt-get install git-core git-svn gitweb

#Creating GIT user

sudo adduser \
--system \
--shell /bin/sh \
--gecos 'git version control' \
--group \
--home /home/git \
git

#setting password
set ur desired password for git user by :

passwd git

#creating directory for repositories

sudo -u git mkdir /home/git/repositories

#to make repositories available, we need git-daemon

sudo -u git git-daemon --reuseaddr --verbose --base-path=/home/git/repositories/ --detach

#Git-daemon needs to be run at startup. For that there is a package named "git-daemon-run".One can install that package
as "apt-get install git-daemon-run" or can use this script. I recommend the script because it seems easy to me

sudo cat > /etc/init.d/git-daemon << EOF

#!/bin/sh

test -f /usr/bin/git-daemon || exit 0

. /lib/lsb/init-functions

GITDAEMON_OPTIONS="--reuseaddr --verbose --base-path=/home/git/repositories/ --detach"

case "$1" in
start) log_daemon_msg "Starting git-daemon"

start-stop-daemon --start -c git:git --quiet --background \
--exec /usr/bin/git-daemon -- ${GITDAEMON_OPTIONS}

log_end_msg $?
;;
stop) log_daemon_msg "Stopping git-daemon"

start-stop-daemon --stop --quiet --name git-daemon

log_end_msg $?
;;
*) log_action_msg "Usage: /etc/init.d/git-daemon {start|stop}"
exit 2
;;
esac
exit 0
EOF

#then run this command to system startup links

update-rc.d git-daemon defaults

#Now change working directory to repositories and create a new project

cd /home/git/repositories
mkdir project1
cd project1

# now create files that you want to in this project1 directory

git init

git add .

git commit -m "your Commit comments"

git remote add origion git@yourserver:repositories/project1.git

touch .git/git-daemon-export-ok

scp -rp .git git@yourserver.com:repositories/project1.git

Git server is now up...

#Now we can test our first clone from client..

git clone git@yourserver:repositories/project1
Regards
Abdulrehman
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

I recommend the script because it seems easy to me
using your script instead of the distribution-provided script is a bad idea, unless you have a good reason for it. on 8.10, installing git-daemon installs and sets up runit-run, which means if anyone follows your instructions, they'll have two copies of git-daemon fighting to bind to the port on startup.
#Now change working directory to repositories and create a new project
doesn't this step (and the following git commands) need to be run as the git user?
git remote add origion git@yourserver:repositories/project1.git
why? and you misspelled "origin".
scp -rp .git git@yourserver.com:repositories/project1.git
and where is this command run? and why didn't you do a "git clone --bare"?

here's how i'd do it. on the clients:

Code: Select all

- install git
- type "git init" wherever they want to create a repo
- type "git add ." and "git commit" wherever they want to add pre-existing files to a repo (not always going to be true)
- type "git clone --bare project project.git" for any projects they want to make available to other developers
- touch projectdir.git/git-daemon-export-ok
- scp projectdir.git server: to copy the bare repo to their home directory on the server.
- edit project/.git/config and add something like 

[remote "public"]
    url = ssh://server/~username/project.git

- now the user can do "git push public" whenever they want to share all their changes.
- setup ssh keys using ssh-keygen on the client (or puttygen, whatever)
- copy the public key into /home/username/.ssh/authorized_keys, or by using ssh-copy-id
the instructions for this are very easy to follow.

on the server:

Code: Select all

- apt-get install git-core git-daemon-run
- edit /etc/sv/git-daemon/run to make any changes (mainly to set the directory to /home instead of /var/cache/git).
- sv restart git-daemon
that's it.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
mejam
Havaldaar
Posts: 127
Joined: Sat Oct 18, 2008 12:30 pm
Location: Lahore
Contact:

Post by mejam »

origin was typed wrong...definately the repos will be created by the git user..
Regards
Abdulrehman
Post Reply