Skip to content

Instantly share code, notes, and snippets.

Forked from jkeesh/
Created November 28, 2012 04:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skopp/4159016 to your computer and use it in GitHub Desktop.
Save skopp/4159016 to your computer and use it in GitHub Desktop.
Python script to create a remote git repo that checks out the latest commit with a post-receive hook
# This script creates a repository and sets it up with a post receive
# hook that checks out the code to the desired directory.
# Really nice for setting up an easy way to push code to a remote
# server without lots of overhead.
# After running this script simply add a remote locally like
# git remote add web ssh://you@server/path/to/repo.git
# Then pushing to the remote is as easy as
# git push web
# Jeremy Keeshin September 23, 2012
import os
import sys
def main():
if len(sys.argv) != 3:
print """
Usage: python repo_name.git /your/checkout/dirctory
repo = sys.argv[1]
checkout_dir = sys.argv[2]
# Make the git directory
os.system('mkdir %s' % repo)
os.chdir('%s' % repo)
# Initialize a new bare repo
os.system('git init --bare')
txt = """#!/bin/sh
GIT_WORK_TREE=%s git checkout -f""" % checkout_dir
# Write the post-receive hook
hook = open('./hooks/post-receive', 'w')
# Make it executable
os.system('chmod +x ./hooks/post-receive')
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment