You have several github profiles for different uses. For example, one account used privately and another account used professionally. Instead of switching profiles all the time which might be error prone, we can setup different git profiles for each folder.
Go to your user home folder. Open .gitconfig
, edit and add includeIf
which points to private.gitconfig
.
Create private.gitconfig
and add your github name and email as below.
These settings point towards any directory within */projects/private
# .gitconfig
[user]
name = philippbusiness
email = [email protected]
[includeIf "gitdir/i:projects/private/"]
path = private.gitconfig
# private.gitconfig
[user]
name = philippprivate
email = [email protected]
Create private.gitconfig
in the same folder where .gitignore
is.
Run these checks to verify the setup:
# navigate to a git repo outside of */projects/private
git config user.name
> philippbusiness
# navigate to a git repo within */projects/private
git config user.name
> philippprivate
Further notes:
- adding
/i
makes the path case-insensititve - having
/
at the end of"gitdir/i:projects/private/"
includes all files and subdirectories recursively