Live data from Hacker News

Conditional Git Configuration

blog.scottlowe.org

41–50 of 73 posts

Re: Conditional Git Configuration

#41
I didn't want to have to organize my work and personal repos using a directory structure, so I use matching on the remote instead. Since my job uses a GitHub organization, I'm able to conditionally include a config file that uses my work email in any GitHub repo under that organization.

I wrote it up here, if that sounds useful: https://www.brantonboehm.com/code/conditional-git-config/

Re: Conditional Git Configuration

#42
post #34

Oh nice, this will remove an annoyance in my dotfiles repo by letting me share my gitconfig between 3 different configurations (home linux amd64 box, work macOS arm64, client macOS arm64) Thank you for sharing it!

What do you have in your git config that requires switching over host architecture?

I put those there as a way to show I couldn't just switch on $ARCH or $OSTYPE similar. I should have explained that better, sorry about that.

Re: Conditional Git Configuration

#45

Interesting, but why not just configure direnv to set appropriate env vars based on your current directory? That works for more than just git.

I prefer the method used in the article. All the settings are neatly kept in a git configuration file, and I don't have to track down where direnv keeps them, or remember that I need a separate tool in order to make it work. Also this allows you to set git config options that don't have a corresponding environment variable.

Re: Conditional Git Configuration

#46

Something that wasn't addressed: when is the configuration read? Does this happen on every command-line git command execution? (I'm guessing "yes", but...)

Yes. Git doesn't daemonize, so there's no way it can avoid reading its configuration every time you run a command. Ultimately what the command ends up doing likely takes orders of magnitude longer than reading and parsing the config file, so it's not really a big deal.

Re: Conditional Git Configuration

#50
post #34

Earlier quoted context omitted.

What do you have in your git config that requires switching over host architecture?

I put those there as a way to show I couldn't just switch on $ARCH or $OSTYPE similar. I should have explained that better, sorry about that.

Ah, gotcha. I thought you might have some weird, nice needs and was curious about it :)
Post reply on HN