Set default git user for different project directories

For example, we have two directory, project_home_a and project_home_b, whenever a new project is created in project_home_a and do a git init, we want it to use userA as the default git user, and whenever a new project is created in project_home_b and do a git init, we want it to use userB as the default git user.

1. Add these in the .gitconfig file at your OS home directory, create it if it doesn’t exist.

[includeIf "gitdir:~/project_home_a/"]
  path = .gitconfig-project_home_a
[includeIf "gitdir:~/project_home_b/"]
  path = .gitconfig-project_home_b

2. Create .gitconfig-project_home_a file and add the userA info

[user]
name = User A
email = usera@gmail.com

3. Create .gitconfig-project_home_b file and add the userB info

[user]
name = User B
email = userb@gmail.com

Now, whenever a new git project is created using git init in ~/project_home_a/, it will use user A as the default git user, and whenever a new git project is created using git init in ~/project_home_b/, it will use user B as the default git user.

Reference:
https://stackoverflow.com/a/43884702

Search within Codexpedia

Custom Search

Search the entire web

Custom Search