Skip to content

Instantly share code, notes, and snippets.

@phillipberndt
Created November 18, 2013 12:32
Show Gist options
  • Save phillipberndt/7527071 to your computer and use it in GitHub Desktop.
Save phillipberndt/7527071 to your computer and use it in GitHub Desktop.
A push-enabled GIT configuration for Apache / cgi-bin / public-html. Place both files in your `public_html` folder, create a corresponding `.htpasswd` file & enjoy.
AddHandler cgi-script .cgi
<Files "git.cgi">
Require valid-user
AuthType Basic
AuthName "GIT Access"
AuthUserFile /path/to/.htpasswd.git
</Files>
#!/bin/bash
# Configuration:
# The base directory for your repositories, must be writable for the server
GIT_PROJECT_BASE=/path/to/git/
# A mail address to send reports on new repositories to
MAIL=pberndt
INFO=(`echo ${PATH_INFO} | sed -nre 's#^/([^/\.]+)(/.+)?#\1 \2#p'`)
REPOSITORY="${INFO[0]}"
export PATH_INFO="${INFO[*]:1}"
if [ -z "$REPOSITORY" -o "$PATH_INFO" = "/" ]; then
cat <<EOF
Status: 200 Ok
Content-type: text/html; charset=utf-8
<h1>GIT repositories</h1>
<p>
Welcome to this GIT repository hub. You seem to have accessed this page
from your web browser. That's not how it's done. See <a
href="http://git-scm.com/book/">http://git-scm.com/book/</a> for an
introduction to GIT.
</p>
<p>
To access these repositories, clone them using git:
</p>
<pre>
git clone http://${REMOTE_USER}@${SERVER_NAME}${SCRIPT_NAME}/${REPOSITORY:-&lt;repository name&gt;}/
</pre>
EOF
exit
fi
export GIT_PROJECT_ROOT=${GIT_PROJECT_BASE}/${REPOSITORY}
export GIT_HTTP_EXPORT_ALL=1
if ! [ -d "$GIT_PROJECT_ROOT" ]; then
if ! mkdir $GIT_PROJECT_ROOT; then
echo -e "Status: 404 Not found\r\n"
exit
fi
(cd $GIT_PROJECT_ROOT && git init --bare && git update-server-info && mv hooks/post-update.sample hooks/post-update) >/dev/null
env | mail -s "New git repositoy $REPOSITORY created in public_html" $MAIL
fi
exec git http-backend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment