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?
Asked
Active
Viewed 261 times
0

kodfire
- 1,612
- 3
- 18
- 57
-
2No. That username is only used when committing. You could run hooks locally that could grab it, but then what would you do with it? – Lasse V. Karlsen Mar 08 '22 at 13:34
-
3What problem are you trying to solve where grabbing the `user.name` value from git config is the solution? – Lasse V. Karlsen Mar 08 '22 at 13:35
-
The *thing* on the server that does the authentication of pushes is the one that knows *who* pushed, but that is completely independent of the client Git settings, or even any of the commits being pushed. (You can be setup to commit with one username, but push with another username.) – TTT Mar 08 '22 at 16:58
-
@TTT @LasseV.Karlsen I need to get the `user.name` from the contributor who is pushing into the server. I'm on the server-side and want to get the contributor's `user.name`. – kodfire Mar 09 '22 at 08:52
-
@LasseV.Karlsen may not have seen your last comment (since I think only the first tagged person gets the notification). Also, I don't think you actually answered the question of *why* you want to see it; you basically just restated the question. What would you do with it if you knew it? Perhaps knowing what you would do with it would enable others to offer different solutions. – TTT Mar 09 '22 at 16:41
-
1As I said, you can't grab that value server-side. You can grab it locally, but how would your local hook transmit that data to the server? There's no way for the hook to add side-channel data to send to the server. Basically, this is going to be exceedingly difficult to do, hence my question as to *why*. – Lasse V. Karlsen Mar 09 '22 at 18:49
1 Answers
0
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 user.email=great@great.org commit -m "great"
... change stuff and git add ...
git -c user.name=gatsby -c user.email=gatsby@great.org 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.

torek
- 448,244
- 59
- 642
- 775
-
That's not important if he faked it or not. Because if he fakes it, the password he is sending in some ways won't authenticate him. – kodfire Mar 10 '22 at 05:44