For web project or other server side project, we need auto-deploy.
For this, we need run some scripts after we push the git commits.
That’s why post-update here.
If we put script file under git-dir/hooks/ and name it with post-update, and chmod -x for it.
The file will run after we push some commits to the git repository.
You can yous any scripting language you like, such as bush, python, ruby, julia, PHP, Node.js…
Compiled as well of cause, but not as easy to read and edit as scripting languages.
#Example 0.
For simple scripts, bash is convenient.
This script will checkout the newest tag to the work directory.
It’s frequently-used.
#Example 1.
This is an example of Laravel project, so we using PHP.
This time, we do different things according to different bushed branch.
When test branch is pushed, we checkout it to the test directory, and apply the migrations of DB.
When migrate branch is pushed, we refresh the DB of the test environment,
When project branch is pushed, we checkout the newest tag to the project environment,
then apply migrations and clear view cache and rebuild route cache.
#Example 2.
Here is the deploy script of this blog, on ruby.
Here we use API instead of CLI to access git.
Maybe a little inconvenience than CLI, but the API is more powerful.
The libgit2 is a great lib of git API, it support more than a dozen of languages and environments.
Above examples are the deploy scripts of real using in my work.
Share the code, and more to the point, share the line of thought.
We hope to bring help.