Multiple accounts on .gitconfig
Posted by Bipul Raman on December 20, 2022.Let's assume a scenario where you have personal github account and another account for git at work.
And you clone all your work related repositories at D:\MyWorkFolder.
In such scenarios, create a dedicated git for work as .gitconfig_work at the same location
where your .gitconfig located. Generally it is located at %USERPROFILE% folder in windows.
Update your .gitconfig to have similar to this. includeIf statement will redirect to
.gitconfig_work for all repos closed in your work folder.
[user]
name = Smart User
email = user@personal.com
[includeIf "gitdir/i:D:/MyWorkFolder/"]
path = ~/.gitconfig_work
Sample .gitconfig content
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[user]
name = Bipul Raman
email = 1234567890@users.noreply.github.com
[includeIf "gitdir/i:D:/OfficeRepos/"]
path = ~/.gitconfig_work
Sample .gitconfig_work content
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[user]
name = Bipul Raman (Office)
email = office@bipul.in
