Skip to content

Instantly share code, notes, and snippets.

@al-the-x
Created July 18, 2012 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save al-the-x/3139235 to your computer and use it in GitHub Desktop.
Save al-the-x/3139235 to your computer and use it in GitHub Desktop.
Magic Deployments

Magic Deployments are Fun!

  1. Make a --bare --mirror clone in some central location on the server, e.g. /var/git/some-site.git
  2. Clone from that central location into your deployment paths, e.g.
  • git clone /var/git/some-site.git /var/www/some-site.com/
  • Check out the correct branch and setup tracking and all that usual stuff...
  1. Add the contents of config into /var/git/some-site.git/config (don't overwrite)
  2. Use git add-deployed to tell the central repo where your deployments are, e.g.
  • git add-deployed master /var/www/some-site.com/
  1. Setup a cron or a hook that triggers update-mirror and update-deployed for your repo, e.g.
  • GIT_DIR=/var/git/some-site.git $(which git) update-mirror to update your mirrored repo.
  • GIT_DIR=/var/git/some-site.git $(which git) update-deployed to update your deployed branches
  • GIT_DIR=/var/git/some-site.git $(which git) update-all to get 'em both
  1. For bonus points, use multiple repos and update them all in one pass:
  • for repo in /var/git/*.git; do $(which git) --git-dir=$repo update-all; done
[alias]
add-deployed = !git config --add deploy.branch
get-deployed = !git config --get-all deploy.branch
update-mirror = "!git fetch -v origin $(git ls-remote -h origin | while read sha ref; do echo $ref:$ref; done)"
update-deployed = "!git get-deployed | while read ref path; do GIT_DIR=$path/.git WORK_TREE=$path git pull origin $ref; done"
update-all = !git update-mirror && git update-deployed
@al-the-x
Copy link
Author

Just remember that the order of the "deploy.branch" config is "$branch $path" and you'll be fine.

@al-the-x
Copy link
Author

I should probably convert these to real git commands eventually... They're very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment