For work I need to use git to manage various aspects of client projects, and because the code is proprietary, I have to manage a private git system. The way you do this is to create a user called git and to setup your authorized keys for that user. Then you make sure the user is using the git-shell with “chsh git -s $(which git-shell)” and make sure that you echo $(which git-shell) >> /etc/shells.

On my local machine I have a script like so:

mkdir -p $1
cd $1
git init
ssh admin@mygitserver -p 1337 "bash /home/admin/make-git-repo $1"
git remote add origin ssh://git@mygitserver:1337/home/git/$1.git
git pull origin master
if [ ! -f .gitignore ]; then
	cp ~/bin/gitignore_template .gitignore
	git add .
	git commit -a -m "Initial Commit of $1"
	git push -u origin master
	git branch master --set-upstream-to=origin/master

On my server, I have a bash script like so:

if [ "$1" = "" ]; then
	echo "You must name the repos, don't add .git!";
	exit 1;
if [ -d "/home/git/$1.git" ]; then
	echo "/home/git/$1.git already exists";
	exit 0;
mkdir /home/git/$1.git
cd /home/git/$1.git
git init --bare
cd ../
chown git:git -R $1.git

That way I can just cd into a directory and type: addrepo some-project. And it gets created on the server, and setup, or if it is already on the server, it pulls it down. Bada-bing.