Git
Funny or usefull usage of git.
Non-bare remote repository
Remote repository are supposed to be bare repo. However it can be usefull to have a non-bare remote sometime.
On the remote machine:
$ mkdir repo
$ cd repo
$ git init
$ git config --local receive.denyCurrentBranch updateInstead
On the local repository:
$ git remote add origin user@server:~/repo
$ git push -u origin master
Auto deploy without CI/CD stuff
We use hooks to execute commands on the repository each time an action is performed.
Here I use hooks to compile the hugo website on a non-bare remote each time it receives a push:
Content of .git/hooks/post-update:
#!/bin/sh
cd "$GIT_DIR/.."
hugo
The hook need to be executanle:
$ chmod +x .git/hooks/post-update
Here I’m directly service public with nginx, but is the static http folder is not in the git repository, we could had a rsync in the hook after the compilation to put the site in the right folder.
Careful
Be careful, hooks execute commands automatically has yourself, I anyone manage to compromize them, they can execute command on your behalf, not good. (Even if you don’t think you use hooks, the files existe anyway…)