Salesforce, Python, SQL, & other ways to put your data where you need it

Need event music? 🎸

Live and recorded jazz, pop, and meditative music for your virtual conference / Zoom wedding / yoga class / private party with quality sound and a smooth technical experience

Configuring multiple Git accounts on my computer

17 Dec 2024 🔖 git
💬 EN

Table of Contents

For the most part, when I contribute to a Git repository from my work computer, it’s a private repository owned by my employer.

However, occasionally the work I do makes me think, “this should be easy to Google,” so I blog it here or post an example in the associated GitHub account, and I don’t want to commit with the wrong Git username or Git email address.

Global Git settings

Here’re the contents of the C:\users\MyWindowsUsername\.gitconfig file:

[user]
	name = My name the way I like it for work
	email = [email protected]
[core]
	excludesFile = "C:/users/MyWindowsUsername/Documents/FaveScripts/.gitignore_global"
[init]
	defaultBranch = main
[includeIf "gitdir:C:/RepoCopies/kkgthb/"]
    path = c:/MyRepos/kkgthb/.gitconfig_include

Always-ignored file paths

Here’re the contents of the C:\users\MyWindowsUsername\Documents\FaveScripts\.gitignore_global file referenced above:

# Folder naming conventions I typically name things I want to ignore
.ignoreme
my_output
dist

# Programming-language-specific folder names I always want to ignore
node_modules

# Mostly ignore any ".vscode" directories, since a lot of plugins put unsafe things in it 
# and since the "settings.json" file is often filled out according to personal taste.
.vscode/*
# But go ahead and let repositories suggest VSCode extensions and such.
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/tasks.json

I cannot tell you how delightful it is to not have to bother with .gitignore every single time I have a quick idea I’d like to play with.

Do I still need to manually add the correct things to the repository’s own .gitignore file when it’s time to show off my work to the world or collaborate with a colleague? Absolutely. It’s not like I want their computer accidentally adding all of the node_modules back to the repo.

But it’s so nice to not think about all that when I’m just getting started, trying to brain-dump an idea as fast as possible.

Commit email and name overrides

Here’re sample contents of files such as C:\MyRepos\kkgthb\.gitconfig_include referenced above:

[user]
	name = kkgthb
	email = [email protected]

These make sure that any time I git clone one into a subfolder of C:\MyRepos\kkgthb\, I don’t have to worry about my blog-related commits accidentally using my work name and email address.

I used to have to remember to go in and manually override these settings for each personal repository’s .gitconfig file when I decided it was time to post something useful to the whole world.

Now I can trust that as long as I put things in the right folder, my commits will use the right name and email. Neat!

--- ---