Permission problem when pulling using post-receive hook

I keep receiving remote: error: cannot open .git/FETCH_HEAD: Permission denied

when post-recive hook is executed

I have stash 2.4 setup to run as dedicated user so post-receive hook is being executed as a stash user.

Hook code


echo "**** Pulling changes into Development Box ****"
echo "User name $USER"

cd /var/www/dir || exit
unset GIT_DIR

git pull origin develop
echo "**** DONE ****"

exec git-update-server-info

I also use .netrc to authenticate stash user (correct access to repo) over HTTP. I'm able to pull with no problems using linux user who run stash if I do it manually but it doesn't work as a hook.

1 answer

Hi Content Formula,

This is not related to network permissions, just the filesystem. The script is running as the same user as Stash, which is then cd'ing in the /var/www/dir, which I can only assume doesn't grant write access. When you say you're able to pull, do you mean from that directory?



PS. You may also be interested in voting for and watching the following:

I suspect someone will eventually release a nice plugin that does this without the need for shell scripts.

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

655 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot