Skip to content

Instantly share code, notes, and snippets.

@johnpeele
Forked from hupili/README.md
Created December 4, 2013 15:48
Show Gist options
  • Save johnpeele/7789847 to your computer and use it in GitHub Desktop.
Save johnpeele/7789847 to your computer and use it in GitHub Desktop.

Use Git to update your web server.

Many hosting service now supports not only FTP and web uploading but also SSH. It's more convenient to use the Git flow:

  • Modify and test your site locally.
  • Push to remote Git repo, which triggers the update of your website.

My settings:

  • Suppose the HTTP server use ${HOME}/html as the root dir of your website.
  • git init the ${HOME}/html as a Git repo with working dir.
  • git init --bare the ${HOME}/html.git as a bare repo for push/pull.
  • Edit ${HOME}/html.git/hooks/post-update as follows.

Handle the nasty environments

If you have control of the server and installs Git via package manager, the above settings should be enough. In my case ( http://hupili.net/ ), the server is really nasty. You can not find evn the which command, let alone Git! After compiling Git, there are some further settings needed.

I put the Git paths in a .git-path file (you may also want to source it in .bashrc)

export GIT_BIN=${HOME}/git
export PATH=${GIT_BIN}/bin:${PATH}
export LD_LIBRARY_PATH=${GIT_BIN}/lib:${LD_LIBRARY_PATH}
export GIT_EXEC_PATH=${GIT_BIN}/libexec/git-core

and modify the .ssh/authorized_keys:

command="if [[ \"x${SSH_ORIGINAL_COMMAND}x\" == \"xx\" ]]; then /bin/bash; else source ~/.git-path; eval \"${SSH_ORIGINAL_COMMAND}\"; fi;" ssh-rsa XXXXX_YOUR_PUB_KEY_HERE YOUR_USER@YOUR_MACHINE_HERE
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".
#exec git update-server-info
target=${HOME}/html
cd $target
unset GIT_DIR
git pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment