Although I'm a happy (also paying) user of GitHub's offerings, there are times when I prefer to host a private repository on a server I control. Setting up your own Git server can be useful if you're isolated from the public internet, if you're subject to inflexible regulations, or if you simply want features different from those offered by GitHub (and other similar providers). Setting up a Git server on a Unix (Linux, Mac OS X, *BSD, Solaris, AIX) machine isn't difficult, but there are many details to observe. Here is a complete guide.
Through the following steps you can setup and use your own
Git server at a server, say
Some of the steps,
like email notifications, users with a restricted shell, and
access control for a particular group,
are optional depending on your requirements and the situation at hand.
For many of the commands you will need administrator (root) privileges,
so prefix them with
sudo or (heaven forbid) run them
from within a root shell.
vigrto edit the group file, or editing directly the file
/etc/group. In the end you want to have a line like the following in the
repogroupis the name of the group that will get access to the specific repository, 10005 is a unique group identification number, and
marry,john,violetare the user identifiers of people that will get access to the repository.
/home/yourname/gitroot) or in a dedicated directory (e.g.
chmod g+rx /path-to/gitroot chown :grouprepo /path-to/gitroot
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 firstname.lastname@example.org,email@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
cd hooks cp post-receive.sample post-receive chmod +x post-receive
#from the last line of the
post-receivescript, so that it will be as follows.
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 # This first time only "origin master" args needed
ssh-keygen(accepting the default responses), and send you the file
sudo su - username mkdir -p .ssh cat >>.ssh/authorized_keys <<\EOF paste-key-as-one-line EOF exit
/usr/local/libexec/git-core/git-shell. Therefore, for each user you want to offer restricted access run a command like the following.
sudo chsh -s /usr/libexec/git-core/git-shell username
git clone myhost.example.com:/path-to/gitroot/newrepo.git
Last modified: Wednesday, June 19, 2013 2:20 pm
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.