Skip to content

Instantly share code, notes, and snippets.

@PureKrome
Last active September 11, 2021 08:31
Show Gist options
  • Save PureKrome/8bba4fd9cf586eb32f720a957a447ed2 to your computer and use it in GitHub Desktop.
Save PureKrome/8bba4fd9cf586eb32f720a957a447ed2 to your computer and use it in GitHub Desktop.
Setting up gitconfig for different work/personal folders/projects

Summary

  • Have different username/email settings for WORK or PERSONAL projects
  • Uses the includeIf hack (unfortunately)
  • To get this to work (or test) the folder needs to have had git init already occur on it.
  • Hack the global .gitconfig file
  • Add separate .gitconfig files where you want have separate settings for different work / personal / serious-projects.
  • For Windows OS, you need to use case -INSENSITIVE- git command => gitdir/i .. most examples say to use gitdir but that fails on Windows OS.

Steps

  1. Create the work folder > C:/Projects/Work/
  2. Create the file .gitconfig in this location.
  3. Edit it with 'work' settings:
[user]
    name = Work Name
    email = work.email@something.com
  1. Follow steps 1->3 for personal stuff > C:/Projects/Personal/
  2. Edit ~/.gitconfig (note: this exists in the "home" folder, regardless of your OS)
  3. Add the includeIf hack, per customization:
[user]
	email = global.common@email.com
	name = Global common name

[includeIf "gitdir/i:c:/projects/work/"]
path = c:/projects/work/.gitconfig

[includeIf "gitdir/i:c:/projects/personal/"]
path = c:/projects/personal/.gitconfig
  1. Test! enter a folder which has already been git init'd and type either/or:
  • git config --get-all user.email
  • git config -l --show-scope

If you see two emails listed, then you're good to go! and it should take the "included" one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment