1

I keep forgetting to switch accounts and make commits with the wrong git profile.

I use VSCode to push commits and i was wondering if there is any extension that can show or change the current Git email/profile ?
Or some way to make it prompt me to enter the email before each commit?

If not, do you know any other free tiny software that can do this?

GitKraken has it, but it is the only feature i really use, and i won't pay just for that.

enter image description here

Gama11
  • 31,714
  • 9
  • 78
  • 100
Cristian Muscalu
  • 9,007
  • 12
  • 44
  • 76
  • The normal way to do this would be to set `user.name` and `user.email` in your repository's Git settings (`.git/config` inside your repository). On the CLI you can use [the `git config` command](https://git-scm.com/docs/git-config) for that; I suspect that Visual Studio Code provides an UI to do the same. Is there some reason that this wouldn't work for you? – ChrisGPT was on strike Sep 19 '17 at 15:06
  • I never set specific users for each repo. Didn't even know about it. I just switch between profiles `git config --global user.email "personal@domain.com"` or `git config --global user.email "work@domain.com"` – Cristian Muscalu Sep 19 '17 at 15:44
  • I _strongly_ recommend setting per-repository `user` values. Almost anything that can be set globally with `git config --global` can be set locally (per-repository) without `--global`. – ChrisGPT was on strike Sep 19 '17 at 16:01
  • Take a look at this answer from [Tomáš Janoušek](https://stackoverflow.com/users/3407728/tom%c3%a1%c5%a1-janou%c5%a1ek): https://stackoverflow.com/questions/4220416/can-i-specify-multiple-users-for-myself-in-gitconfig/43654115#43654115 I used it for my own purposes and it works ok as long as you have your projects in separate folders for the different profiles. – spences10 Jan 28 '19 at 14:35

1 Answers1

3

Usually you just set the username for the repository itself, and not globally, using:

git config user.email name@domain.com

If for some reason you don't want to do this, because you want to commit something with email A and something else with email B for example, perhaps you could use an alias that switches the profile and does the commit? Something like this:

git config alias.c "-c user.email=name@domain.com commit -m"

c being my typical alias for commit. So you'd use this like this:

git c "my commit message"

You could create two aliases like this one to switch quickly between two different emails.

Verv
  • 2,385
  • 2
  • 23
  • 37
  • 2
    The alias is nice way to keep things short, but i will still forget to use it. But as you said i should probably stop messing with the global `user.email` and add it in each repo. – Cristian Muscalu Sep 19 '17 at 15:48
  • I'm not crazy about the alias suggestion here. IMO the right solution is to set repository level `user.name` and `user.email` values, as in your first option and my comment above. – ChrisGPT was on strike Sep 19 '17 at 16:08
  • I'm not either, but as mentioned in my answer, he may, for whatever reason, want to commit quickly with two different users on a regular basis. – Verv Sep 19 '17 at 17:36