Setup git server with git-shell interactive in ubuntu

Git is popular DVCS (Distributed Version Control System) that become DeFacto standard VCS in the world. There is another DVCS like git out there, it's mercurial, but i prefer git for their community support. Git is flexible, it can act as a server and a client.

To setup git as a server you just need to initialize yout repository with option --bare and your repository will become server side repository. i won't write about setup user in this post, it's on another post, so here we go setting up git server with git-shell interactive.

I assume your git user is git, if your current git user using bash as shell, loginto it and create git-shell-command folder

$ mkdir git-shell-command

Every shell script inside those folder will be available via git-shell interactive

$ cd git-shell-command
$ vim greeting

Here is content of greeting file

#!/bin/bash
# this file reside in ~/git-shell-command/
# if name of this file is greting so the full path will be ~/git-shell-command/greeting
echo "Hai stranger";

Save this file with :wq command in vim and set it as execute and read only. if you want to edit it change 500 with 700

$ chmod 500 ~/git-shell-command/greeting

now, as a root, change git user shell to git-shell

# usermod -s $(which git-shell) git

From this point if your git user was set, you can login to ssh and test it with :

$ ssh git@server
git> greeting
Hai stranger
git>

git-scm.com explain detail part of git-shell, and this post explain more detail step. this gist may also inspire you to create another command.

Comments