Skip to content

Instantly share code, notes, and snippets.

@romadryud
Last active August 15, 2022 07:35
Show Gist options
  • Select an option

  • Save romadryud/357716890c8cd83e61730a4357af8276 to your computer and use it in GitHub Desktop.

Select an option

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 = personal@email.com

.gitconfig-work:

[user]
  email = work@company.com

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

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