Skip to content

Instantly share code, notes, and snippets.

@dev-sampsonorson
Forked from Icaruk/multipleGitProfiles.md
Created March 16, 2022 16:59
Show Gist options
  • Save dev-sampsonorson/86b765f48ddbe840897205eaa2ef5ea8 to your computer and use it in GitHub Desktop.
Save dev-sampsonorson/86b765f48ddbe840897205eaa2ef5ea8 to your computer and use it in GitHub Desktop.
How to have multiple profiles on git

Step 1

Go to your work folder, mine is located at: F:/Work/EnterpriseName/

And then create a .gitconfig-work with the following data:

[user]
	name = Name at work
	email = email@atwork.com

The folder should be like this:

πŸ“‚ EnterpriseName
β”œβ”€β”€ πŸ“‚ project01
β”œβ”€β”€ πŸ“‚ project02
β”œβ”€β”€ πŸ“‚ project03
└── πŸ“„ .gitconfig-work

Step 2

Navigate to your current .gitconfig and open it. Usually it's at C:\Users\your-user

It should have something like:

[user]
	name = Icaruk
	email = myemail@hotmail.com

That's the global config, that will be used as the default one. If it doesn't exist, create it with these commands:

git config --global user.name "Icaruk"
git config --global user.email "myemail@hotmail.com"

Step 3

Add the following lines:

[includeIf "gitdir:F:/Work/EnterpriseName/"]
	path = F:/Work/EnterpriseName/.gitconfig-work
  • The first path is your work path, it must end with "/".
  • The second path is your .gitconfig-work that you created on your work folder. But it can be anywhere, just point at it.

Step 4

Go to your work folder and open any project, then run: git config user.email

It should display your work email.

Now go to any project that isn't located inside your work folder and run the same command. It should display your default email.

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