| You can set up different Git profiles (name/email) per folder using Git’s config hierarchy. Git supports three levels of config: - System (
--system): applies to all users on the machine. - Global (
--global): applies to your user account everywhere. - Local (
--local): applies only to a specific repo (this overrides global/system).
Since you want three different folders (projects) to have their own profiles, you’ll use local config inside each repo. 
Option 1 – Set local config in each repoIn each repo’s folder, run: cd /path/to/repo1
git config user.name "Alice Work"
git config user.email "alice@work.com"
cd /path/to/repo2
git config user.name "Alice Personal"
git config user.email "alice@gmail.com"
cd /path/to/repo3
git config user.name "Alice OpenSource"
git config user.email "alice@opensource.org"
These settings are stored in .git/config inside each repo. They override your global profile. Option 2 – Use directory-based config (includeIf)1. Open your global git configgit config --global --edit
This opens ~/.gitconfig in your editor. 2. Add directory-based rulesInside ~/.gitconfig, add something like this: [user]
name = Alice Default
email = alice@default.com
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
[includeIf "gitdir:~/personal/"]
path = ~/.gitconfig-personal
[includeIf "gitdir:~/oss/"]
path = ~/.gitconfig-oss
gitdir:~/work/ means “any repo inside ~/work/”.
3. Create separate config filesNow create each file with its profile. ~/.gitconfig-work [user]
name = Alice Work
email = alice@work.com
~/.gitconfig-personal [user]
name = Alice Personal
email = alice@gmail.com
~/.gitconfig-oss [user]
name = Alice OpenSource
email = alice@opensource.org
4. Verify settingsGo into any repo and run: git config user.name
git config user.email
It should show the correct profile depending on the folder. Tips: - Paths must end with a slash (
/) to match a folder and all its subfolders. - If your repos are nested deeper (e.g.
~/work/projects/foo), it still works. - If you want to match a single repo only, use
gitdir:~/work/myrepo/.git instead. |