Article Image
Image: Black-Pixel

Every time I clone or initialize a git repository I forget to set my user name and email address. I know, I can set a default user name and email in the global ~./gitconfig. But this doesn’t work for me, because I use my Mac for work, Ph.D. related and private projects. That means I have three different email address which I mainly use.

To compensate my forgetfulness I wrote a small script which prompts me for the email address to use every time I enter git clone or git init into the command line. I think it’s worth to share it with you.

First, add the following script to your $PATH. This script will show the prompt. Don’t forget to change the email addresses of the array named MAILS.

Now the magic. Git doesn’t allow us to override the init and clone command parameters. The trick is to use a shell function which overrides the git command and executes the above script when the specific command parameters are given:

That’s it. Next time you initialize or clone a repository you should see something like this:

git email prompt

I fixed the git shell function to be failsafe when using options for init or clone.

Blog Logo

Marvin Frommhold

"Aufgrund falschen Medienkonsums und Bildungsmangel gibt es in Deutschland immer mehr assipöse Menschen."



random stuff by a linked data engineer

Back to Overview