Skip to content

Instantly share code, notes, and snippets.

@ahyield
Created August 20, 2025 14:44
Show Gist options
  • Select an option

  • Save ahyield/591b53e54368ac55226fc7a4a1a011e5 to your computer and use it in GitHub Desktop.

Select an option

Save ahyield/591b53e54368ac55226fc7a4a1a011e5 to your computer and use it in GitHub Desktop.
Git for work and personal when using multiple ssh keys
[includeIf "gitdir:~/Workspace/work/"]
path = ~/dotfiles/.gitconfig-work
[includeIf "gitdir:~/Workspace/personal/"]
path = ~/dotfiles/.gitconfig-personal
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
[init]
templatedir = ~/.git/templates
defaultBranch = main
[color]
diff = auto
status = auto
branch = auto
ui = auto
[core]
excludesfile = ~/.gitignore_global
editor = vim -u NONE
[help]
autocorrect = 1
[push]
default = matching
[branch]
autosetupmerge = always
autosetuprebase = always
[merge]
tool = chdiff
trustExitCode = 0
[mergetool "filemerge"]
cmd = /usr/bin/env chdiff --wait "$LOCAL" "$REMOTE"
keepBackup = false
trustExitCode = false
[rerere]
enabled = 1
[filter "media"]
required = true
clean = git media clean %f
smudge = git media smudge %f
[user]
signingkey = 0000000 # Same like above
name = your-user-name
email = email@examble.com
[commit]
gpgsign = true
[gpg]
program = /usr/local/MacGPG2/bin/gpg2
[alias]
assume = update-index --assume-unchanged
unassume = update-index --no-assume-unchanged
glog = log --pretty='format:%d %Cgreen%h%Creset %an - %s' --graph
assumed = "!git ls-files -v | grep ^h | cut -c 3-"
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
[init]
templatedir = ~/.git/templates
defaultBranch = main
[color]
diff = auto
status = auto
branch = auto
ui = auto
[core]
excludesfile = ~/.gitignore_global
editor = vim -u NONE
[help]
autocorrect = 1
[push]
default = matching
[branch]
autosetupmerge = always
autosetuprebase = always
[merge]
tool = chdiff
trustExitCode = 0
[mergetool "filemerge"]
cmd = /usr/bin/env chdiff --wait "$LOCAL" "$REMOTE"
keepBackup = false
trustExitCode = false
[rerere]
enabled = 1
[filter "media"]
required = true
clean = git media clean %f
smudge = git media smudge %f
[user]
signingkey = 0000000 # replace with you signing key
name = your-user-name
email = your-email
[commit]
gpgsign = true
[gpg]
program = /usr/local/MacGPG2/bin/gpg2
[alias]
glog = log --pretty='format:%d %Cgreen%h%Creset %an - %s' --graph
assume = update-index --assume-unchanged
unassume = update-index --no-assume-unchanged
assumed = "!git ls-files -v | grep ^h | cut -c 3-"
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true

What

When you have multiple accounts or multiple ssh keys for git, and you want separation and not to deal with git config --local user.email "blablabla",

How

You need to directories on your home for example

  ~/Workspace/work
  ~/Workspace/personal

Then Put each git-config somwehere, I choose ~/dotfiles

  ~/dotfiles/.gitconfig-work
  ~/dotfiles/.gitconfig-personal

Then your main ~/.gitconfig would just use:

[includeIf "gitdir:~/Workspace/work/"]
   path = ~/dotfiles/.gitconfig-work
[includeIf "gitdir:~/Workspace/personal/"]
   path = ~/dotfiles/.gitconfig-personal

That tells git to load the proper config file when a directory is accessed, like, when you go to

  cd ~/Workspace/work

Git will load the .gitconfig-work automatically...

Gotchas

The config files here are mine, so adapt them to your tase..

Cheers

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