Git Switch

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.


case "$1" in  
git config --global "Your Name"  
git config --global  
git config --global "Your Other Name"  
git config --global  

git config --global  
git config --global

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.

Leave a Reply

Your email address will not be published. Required fields are marked *