It is be possible to organize Git-cloned projects into folders based on work/personal criteria, for instance one folder could be completely dedicated to personal projects, while the other to work related projects.
We could have these two folders in our case:
~/projects/personal/
- personal projects directory~/projects/work/
- work projects directory
Let's define configuration with sane defaults for git-cloned repositories outside of these two folders.
$ cat ~/.gitconfig
[user]
name = default.user.name
email = [email protected]
[core]
autocrlf = input
editor = nano
longpaths = true
[pull]
rebase = true
[init]
defaultBranch = master
[includeIf "gitdir:~/projects/personal/"]
path = ~/.gitconfig-personal
[includeIf "gitdir:~/projects/work/"]
path = ~/.gitconfig-work
Personal projects configuration
$ cat ~/.gitconfig-personal
[user]
name = personal.user.name
email = [email protected]
Work projects configuration
$ cat ~/.gitconfig-work
[user]
name = work.user.name
email = [email protected]
Now, if you would push changes from the personal folder then git will use [email protected]
as identity,
and [email protected]
respectively for work folder. For example:
Personal:
$ cd ~/projects/personal/xyz
$ git config --get user.email
[email protected]
Work:
$ cd ~/projects/work/abc
$ git config --get user.email
[email protected]