Automatically publish markdown files in git repo to webserver
I have a git repo that has a
docs directory where I keep markdown files that document things I’m working on (for example, I have one called
setup_git_server.mdown). I push and pull the repository (and others) from my own webserver running gitolite.
What I want to happen is that whenever I push a commit to the server, it automatically converts the markdown files to HTML and copies them to a directory on the server where Apache can server them.
What’s the best way to do this?
2 Solutions collect form web for “Automatically publish markdown files in git repo to webserver”
You will want to setup a git hook on the server your repository is hosted. A hook will only run on the machine where it is installed. The hooks themselves are not part of the checked in code base. For example, any post commit hooks you have on your local machine will not be pushed or executed on the server. Other people who check our your code base will not get your hooks.
If you want the server to take an action when it receives a push, you should create a post-receive hook. The hook can be any executable. In your case, you may want to clone your repo to a temp directory, extract the markdown file, and publish it to your web server.
I’m not sure if it’s the same for gitolite, but in gitosis, the hooks directory is in the top level of each hosted repository. Place your post-receive hook in that directory.
Look in your .git directory for a subdirectory named “hooks”. You’ll find sample shell scripts in there that respond to various events. Choose one, e.g. post-commit and tune it to update your documents.
See git hooks and how they work or just Google for “git hooks”