sourcegit icon indicating copy to clipboard operation
sourcegit copied to clipboard

[Feature Request] Multi-user Profile Switcher

Open ousugo opened this issue 11 months ago • 1 comments

Hope to save multiple git user profiles, and then could quickly switch in Repository Configure

Image

Image

ousugo avatar Jan 16 '25 18:01 ousugo

Not really the same but I wanted to share my "workaround".

You can add this kind of configuration to your global .gitconfig like so:

[includeIf "hasconfig:remote.*.url:[email protected]*/**"]
	path = ~/gittools/.gitconfig-github
[includeIf "hasconfig:remote.*.url:https://github.com*/**"]
	path = ~/gittools/.gitconfig-github
[includeIf "hasconfig:remote.*.url:[email protected]*/**"]
	path = ~/gittools/.gitconfig-gitlab

This includes a specific sub-config only if a remote's url matches a specific pattern.

And then, inside the ~/gittools/.gitconfig-xyz there's your remote-specific user config:

[user]
	name = <username>
	email = <email>

Now if you leave your user info empty in the repo's config, the right one will be picked automatically if it matches one of the includeif-rules above. I love this feature :) And as it's only using gitconfig-features it is client-agnostic. Once set up, it just works the same for sourcegit, fork etc.

krisrok avatar Apr 09 '25 09:04 krisrok