I'm sure everyone has a
.gitconfig with some handy aliases like:
alias.ff=git pull --ff-only alias.rb=git pull --rebase
If you open up your
.gitconfig it'll look something like:
[alias] ; too lazy to type these all in full root = !pwd ff = pull --ff-only rb = pull --rebase stat = status
It looks like an ini file, really.
The cool thing about
.ini is that everyone has their own freak-show extensions to the simple ini format, which is really not much more complex than what's above, but has been extended in different directions with each implementation.
git-config obviously has its own rules about what's allowable, and how things are stored.
You're not allowed underscores:
me@compy386:~ $ git config -f ./example --add foo.bar_baz 1 error: invalid key: foo.bar_baz me@compy386:~ $ git config -f ./example --add foo_bar.bar 1 error: invalid key: foo_bar.bar
So, unless your language lets you have
- in method names, or you like
snakeCase you're going to have to mangle the names after reading your config.
Your settings need to be in a section
me@compy386:~ $ git config -f example --add bar 1 error: key does not contain a section: bar
Doing this makes the config file much easier to deal with, and leaves you without the quagmire of nonsense dealing with "keys with no section go into the _ section"
Sections can have sub-sections
If you want to have configs for multiple named things of the same type:
me@compy386:~ $ git config -f ./example --add foo.thething.bar-baz 1 me@compy386:~ $ cat ./example [foo "thething"] bar-baz = 1 me@compy386:~ $ git config -list -f ./example foo.thething.bar-baz=1
Yep, you can have 2 levels of keys, and you end up with
[first "second"] in your config. Neat!
This is used for branches and remotes among other things:
.git/config [branch "master"] remote = origin merge = refs/heads/master
sections can have the same name as sub-sections
me@compy386:~ $ git config -f example --add foo.bar.baz 1 me@compy386:~ $ cat example [foo] bar = 1 [foo "bar"] baz = 1 me@compy386:~ $ git config -l -f example foo.bar=1 foo.bar.baz=1
If you're parsing this directly into a data structure you can end up with some fairly upsetting situations, like foo.bar becoming a hashmap when you don't expect it.
git-config - you might as well use it.
If you're building a tool that depends on git for a large portion of its job, you might as well use git-config too. It's a format that your users are likely already familiar with, and fits neatly into the ecosystem.