Resolving Git hooks error: unable to unlink old ‘filename’ (permission denied)

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.

I was following the tutorial to setup a Git server on Raspberry Pi1. Then I continued to setup automatic deployment with Git from above article 2.

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 (pi to git), the 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

Published by


A Muslim, sober, a Javanese

Share your idea here (markdown enabled)

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s