Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: who pushed in post-receive hook

Tags:

git

githooks

How do I determine who pushed to the repository?

I.e. Somebody does git push origin master and in the post-receive hook on the origin repo I need to use the name or e-mail of Somebody.

like image 676
takeshin Avatar asked Sep 21 '10 15:09

takeshin


1 Answers

If you're using the SSH protocol to push changes to the server, with each user having their own account on the server, then your script should be running as the user who's doing the push. So, you should be able to use whoami or id -un to get the username of the person doing the push.

If you are not using this setup, the best way to keep track of who is pushing is probably using Gitolite, a powerful Git authentication and authorization system. In Gitolite, you can use the update.secondary and post-update.secondary hooks, which will have the GL_USER environment variable set to the current Gitolite user.

like image 126
Brian Campbell Avatar answered Nov 10 '22 10:11

Brian Campbell