Created
September 13, 2023 19:33
-
-
Save yashbedi/7cc5cd3eeba5989a7d19a8fc41d6ea55 to your computer and use it in GitHub Desktop.
Script for switching between git profiles, bash script, seamless switching, changing git accounts,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Define profile names and corresponding Git configuration values | |
profile1_name="Personal" | |
profile1_username="YOUR_USER_NAME" | |
profile1_email="YOUR_EMAIL_PERSONAL" | |
profile2_name="Work" | |
profile2_username="YOUR_USER_NAME" | |
profile2_email="YOUR_EMAIL_WORK" | |
# Function to set Git profile | |
set_git_profile() { | |
local name="$1" | |
local username="$2" | |
local email="$3" | |
git config --global user.name "$username" | |
git config --global user.email "$email" | |
echo "Switched to Git profile: $name" | |
} | |
# Display menu to select a profile | |
echo "Select a Git profile:" | |
echo "1. $profile1_name" | |
echo "2. $profile2_name" | |
echo "3. Quit" | |
read -p "Enter the number of the profile you want to switch to: " choice | |
case $choice in | |
1) set_git_profile "$profile1_name" "$profile1_username" "$profile1_email" ;; | |
2) set_git_profile "$profile2_name" "$profile2_username" "$profile2_email" ;; | |
3) echo "Quitting the script." ;; | |
*) echo "Invalid choice. Quitting the script." ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After running the script you can check your
.gitconfig
in root directory the global username & email would have been changed.