Sunday, April 9, 2017

How to Create Your Own Git Server

1.add repogroup
groupadd(/etc/group): repogroup:*:10005:marry,john,violet
chmod g+rx /path-to/gitroot  #/home/yourname/gitroot
chown :grouprepo /path-to/gitroot
2.init repo
cd /path-to/gitroot
git init --bare newrepo.git
cd newrepo.git
chown -R :grouprepo .
git config core.sharedRepository group
find . -type d -print0 | xargs -0 chmod 2770
find . -type f -print0 | xargs -0 chmod g=u   
echo 'One-line project description' >description
git config --local hooks.mailinglist email-a@example.com,email-b@example.com,...
git config --local hooks.emailprefix '[DI-PR] '
git config --local hooks.showrev "git show -C %s; echo"
git config --local hooks.emailmaxlines 100
Setup a so-called hook to create these email notifications.
cd hooks
cp post-receive.sample post-receive
chmod +x post-receive   
. /path-to-hooks/post-receive-email
3.commint repo
cd to-your-personal-working-directory
git clone myhost.example.com:/path-to/gitroot/newrepo.git
echo "Short project description" >README.txt
git add README.txt
git commit -a -m "Add README file"
git push origin master
4.add new user
useradd or adduser
ssh-keygen(.ssh/id_rsa.pub)
sudo su - username
mkdir -p .ssh
cat >>.ssh/authorized_keys <<\EOF
paste-key-as-one-line
EOF
exit
sudo chsh -s /usr/libexec/git-core/git-shell username
5.new user to clone
git clone myhost.example.com:/path-to/gitroot/newrepo.git

No comments:

Post a Comment