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.
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.
I am not sure Git is meant to manage that kind of access control.
That is why you have ssh-based wrappers like gitosis or gitolite that will provide the adequate authentication level you are after.
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.
You cannot tell that using Git. If you use SSH to push, then you can use SSH to get the username, if you use a user-management frontend such as gitolite, you can use that to get the username, if you use HTTP with authentication, you can use your webserver to get the username, but the Git networking protocols do not transmit any usernames.