Atomic website update with Git

I’d like to update a live website in an atomic way. If we’ve made several changes to pages, images, and javascript, all of the changes should appear simultaneously with no downtime, inconsistency, or 404s.

If I simply copy the changed files into the website directory, then at least a few requests will see an inconsistent site. If I copy the new site to a separate directory, then rename the old directory to take it out of production and rename the new directory to make it live, then for one brief moment we’ll get 404s.

  • why does git allow remote tags to move, or why you can't use git-tag for atomic test-and-set
  • What is the value of atomic commits in Subversion?
  • I really have two questions:

    How can I update a directory of files in an atomic way?

    How can I coordinate this with Git? We’d like to deploy using a git pull (or possibly push). The path of the site within the git repo is different from the path on the server, so a bit of moving/renaming needs to happen, either using git commands or OS commands.

  • git push error: RPC failed; result=22, HTTP code = 403
  • pip tries to use git when git is not installed
  • Git Submodule: Which commit (hash) do I need?
  • How to use brace expansion in gitrevisions <text>
  • Git: How to delete committed file permanently?
  • Reopen a Pull Request
  • 3 Solutions collect form web for “Atomic website update with Git”

    You can do what you’re imagining using symlinks. Moving one symlink over another is an atomic operation, so you should be able to avoid any 404 errors.

    Your hook would deploy your site to a directory, perhaps named after the commit hash. Then it would make a symlink to that, perhaps called staging. Then it would move that symlink over the production symlink.

    hash=`git rev-parse HEAD`
    git checkout-index -a -f --prefix=/srv/www/$hash/
    ln -s /srv/www/$hash /srv/www/staging
    mv -T /srv/www/staging /srv/www/production
    

    Like Owen said, you may use a symlink to the last release you deployed. I’ve written a blog post about this recently: http://bugfixer.endel.me/2013/08/04/simple-atomic-deployment-with-git

    You may configure a post-receive hook on your remote git server that creates the symlink when the new release is ready.

    I am not totally sure about it, but you could create post push hook for git, which creates new dir, or copy existing one, pull or clone your project and change link from your project to new dir. Your project dir is just link to one of deployed dirs.

    But my method sounds like workaround.

    Git Baby is a git and github fan, let's start git clone.