Skip to content

Instantly share code, notes, and snippets.

@romadryud
Last active August 15, 2022 07:35
Show Gist options
  • Save romadryud/357716890c8cd83e61730a4357af8276 to your computer and use it in GitHub Desktop.
Save romadryud/357716890c8cd83e61730a4357af8276 to your computer and use it in GitHub Desktop.
Using git with personal and work profile

Hi folks! Imagine you have work and personal profile for git on one OS and you want to git select proper email when you do git stuff.

File structure:

home-directory
├── .gitconfig
├── .gitconfig-personal
└── .gitconfig-work

.gitconfig:

...
[user]
  name = Name Surname
[includeIf "gitdir:projects/"]
  path = .gitconfig-personal
[includeIf "gitdir:work/"]
  path = .gitconfig-work
...

.gitconfig-personal:

[user]
  email = [email protected]

.gitconfig-work:

[user]
  email = [email protected]

With this setup, when we do git stuff, we will have:

.
└── projects - all projects under this directory except work will have [email protected]
    ├── pet-project - we will have [email protected]
    └── work - all projects under this derictory will have [email protected]
        └── work-project - we will have [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment