Git - How to get user.name of the pusher when in git server?

367 views Asked by At

I have a CentOS server that has a Git server in it. When a user is running git push, I want to get the user.name of his config. Is it possible to get that within the hooks like update or pre-receive file?

1

There are 1 answers

1
torek On

You can't. The user.name setting is irrelevant anyway, since it's not necessarily the name of the person running git push; what matter are:

  • the user name that authenticated, which you'll find in some authentication-specific method; and
  • the names (pairs of them, author and committer) in each new commit.

If I make two commits in a row with faked names:

... change stuff and git add ...
git -c user.name=great -c [email protected] commit -m "great"
... change stuff and git add ...
git -c user.name=gatsby -c [email protected] commit -m "gatsby"

and then run git push with a third faked name:

git -c user.name=fitzgerald push origin master

what do you intend to do with the three names I've supplied?

In any case, the client-side user.name setting is simply not available to the server. Since it can be so easily faked (see above), git push does not bother to supply it.