Inhereting local git config
If you’re like me, you have at least two GitHub accounts. When I’m spinning up little experiments, it’s all too easy to commit with the wrong committer information. My commit history is littered with these mistakes.
It’s not a big deal, but it’s annoying to the point where I have searched and found for a solution. Guess what, it’s incredibly easy!
Inheriting git config
Here’s an imaginary structure
top |_ account-1 |_ repo-a |_ account-2 |_ repo-1 |_ repo-2 |_ repo-3
account-2 aren’t repositories, but their children are. I want to use different email addresses for commits if they sit in different account folders.
Step 1: create the config to include
# top/account-2/.gitconfig [user] email = "[email protected]"
Step 2: include this config at the right time
# ~/.gitconfig # ...rest of file [includeIf "gitdir:~/top/account-2/"] path = "~/top/account-2/.gitconfig"
That’s it - done!
Future Matt will thank me later.