4

I have the following .gitconfig:

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

Getting name and email is easy using git's built in commands.

How can I get the value of custom_field?

Christopher
  • 40,100
  • 10
  • 77
  • 96
Alex
  • 32,503
  • 25
  • 86
  • 132

1 Answers1

8

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
  • 40,100
  • 10
  • 77
  • 96
  • 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