I have a need to change my git profile depending on what I’m working on. I created a simple script that I could run in the shell to switch between my profiles.
#!/bin/bash case "$1" in 'place1') git config --global user.name "Your Name" git config --global user.email firstname.lastname@example.org ;; *) git config --global user.name "Your Other Name" git config --global user.email email@example.com ;; esac git config --global user.name git config --global user.email
If you put this script in your
PATH, you can then run
git switch place, where
place is the profile you would like to use. In the script above,
place1 is your first profile and anything else is the second profile. This allows you to run
git switch, which just switches to the last, default profile.
The magic of git is that if you run
git something, it looks for the command
git-something in your path and runs it. If you save the above script as
git-switch in your
PATH and make it executable, you can execute the command as if it were apart of your git tool chain.