Deploying your projects via git (or any kind of version control, for that matter) is a no-brainer. It's been discussed many times (this is probably my favourite) and as we all know, it takes all the manual labour, time and human error out of the process.
You don't often find deployment scripts though. Perhaps it's just me failing at Google, I don't know; but perhaps people just don't tend to write them generic enough. Or perhaps they are too simple to be bothered sharing them. In any case, I didn't like the idea of writing single-use shell scripts and so I whipped up something that does the job rather well, and in a generic and reusable way.
It will alert you as to what you're pushing and what is happening, and check for any changes before proceeding. To setup, just configure two properties in you git repository as follows:
git config --bool receive.denyCurrentBranch false
should allow you to re-push an existing commit for it to be redeployed. This makes rolling back much easier.git config --bool core.bare false
must be set beforecore.worktree
for bare repositories, since they will need a directory to checkout into.git config --path core.worktree {DEPLOY_DIR}
will set the directory to checkout the working copy into. Best to make this an absolute path.
You can now push branches or tags up to the remote and it will deploy to the configured directory. Here is the script!