In the user home, define a parent .gitconfig
file for your main account (eg: work account)
[user]
name = John Doe
email = [email protected]
[credential]
helper = store --file /home/johndoe/.git-credentials
helper = cache --timeout 30000
Then add an [includeIf]
section at the end of this main .gitconfig
file.
This section allows including another git configuration file for all repositories inside a given directory.
[user]
name = John Doe
email = [email protected]
[credential]
helper = store --file /home/johndoe/.git-credentials
helper = cache --timeout 30000
; include for all repositories inside ~/git-clones/github.com/
[includeIf "gitdir:~/git-clones/github.com/"]
path = .gitconfig-github
Now create in user home (relative paths are always relative to the including file) the .gitconfig-github
file with the necessary options.
[user]
name = jdoe
email = [email protected]
[credential]
helper = store --file /home/johndoe/.git-credentials-github
helper = cache --timeout 30000
You can check the configuration is defined correctly by using a git config
command inside one of the cloned repository in a group directory.
johndoe@COMPUTER:~/git-clones/github.com/my-project$ git config user.name
jdoe