5

I have the following .gitconfig:

[user]
name = name
email = email@email.com
custom_field = AAA

Getting name and email is easy using git config.

How can I get the value of custom_field :

$ git config --global user.custom_field 
error: invalid key: user.custom_field
SebMa
  • 4,037
  • 29
  • 39
Alex
  • 34,581
  • 26
  • 91
  • 135

1 Answers1

10

Your command is failing because you've put an underscore in the custom field's name. To add a custom field to the .gitconfig file, use this command:

git config --global user.customfield <value>

You can then retrieve it with:

git config --global user.customfield

For example:

$ git config --global user.customfield test
$ git config --global user.customfield
test

Also, avoid _'s in the custom field name. Git doesn't parse them:

$ git config user.custom_field test
error: invalid key: user.custom_field
Christopher
  • 42,720
  • 11
  • 81
  • 99
  • Thanks but that's retrieving it on the local side. I need to get it in a hook on the server – Alex Jul 06 '12 at 14:44
  • What are you trying to accomplish specifically? When you say "getting name and email is easy using git's builtin commands", to what are you referring? – Christopher Jul 06 '12 at 14:46
  • If the .gitconfig file you're talking about it local, but you're trying to access that data server-side, you're out of luck. You could, however, enforce a commit message template: http://stackoverflow.com/a/3967136/877115 and then reject commits without `custom_field` server-side: http://stackoverflow.com/a/11314667/877115 – Christopher Jul 06 '12 at 14:59