This article will teach you how to use Git when you want to deploy your application. While there are many ways to use Git to deploy our application, this tutorial will focus on the one that is most straightforward. I assume you already know how to create and use a repository on your local machine.
The setup was going well, until I tried to commit new changes and then pushed it to the Pi server. I got a bunch of errors produced by
post-receive hook script, similar like these:
remote: error: unable to unlink old 'filename' (Permission denied)
I googled it, and there has been a discussion on Stackoverflow3. But, the accepted answer and the comment below it hasn’t answered my problem yet. Then I kept googling to find another workaround. Still, no luck. But then, fortunately I figured out the main problem: it was file permission problem as reported by error log. (Of course, it is… just kidding)
The first tutorial instructed to create a new user for git server. Although I can execute
git pull and
git pull directly across the users (
post-receive script still triggered error.
Actually, the solution is simple. The user
git need to have write permission to the
pi‘s files and directories of the git repository. But, although I have changed the file permissions of both git repo and the production directory, it still triggered error. So, then I added the
git user to the group
pi. And eventually the error was solved.
sudo usermod -a -G pi git