<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: DevOps-Boy</title>
    <description>The latest articles on DEV Community by DevOps-Boy (@devops-boy).</description>
    <link>https://dev.to/devops-boy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1128125%2Fc01d6669-5c80-41be-b04c-8012452322a5.jpeg</url>
      <title>DEV Community: DevOps-Boy</title>
      <link>https://dev.to/devops-boy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devops-boy"/>
    <language>en</language>
    <item>
      <title>Git User Switching Script Setup Guide</title>
      <dc:creator>DevOps-Boy</dc:creator>
      <pubDate>Mon, 28 Apr 2025 20:55:47 +0000</pubDate>
      <link>https://dev.to/devops-boy/git-user-switching-script-setup-guide-41cn</link>
      <guid>https://dev.to/devops-boy/git-user-switching-script-setup-guide-41cn</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This document explains how to set up a script to switch between multiple Git users easily. The script allows you to switch between different configurations, such as Developer, Freelancer, and other dummy users. With this solution, users can easily switch Git user configurations for different purposes like personal development, work, and more.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;Before proceeding with this setup, ensure that you have the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Unix-based system (Linux/MacOS) with Git installed.&lt;/li&gt;
&lt;li&gt;A text editor (like nano or vim) for editing files.&lt;/li&gt;
&lt;li&gt;Access to the terminal for running commands.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Step-by-Step Guide&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the Switching Script
Open a terminal and create a new script file using a text editor (e.g., nano):
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano ~/git-use.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add the following content to the script:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Git User Details (User should modify these variables)
DEVOPS_NAME="devops"
DEVOPS_EMAIL="yourdevops@gmail.com"

FREELANCER_NAME="freelancer"
FREELANCER_EMAIL="yourfreelancer@gmail.com"

DUMMY1_NAME="dummyuser1"
DUMMY1_EMAIL="dummy1@example.com"

DUMMY2_NAME="dummyuser2"
DUMMY2_EMAIL="dummy2@example.com"

DUMMY3_NAME="dummyuser3"
DUMMY3_EMAIL="dummy3@example.com"

# Function to set Developer user
set_devops() {
  git config --global user.name "$DEVOPS_NAME"
  git config --global user.email "$DEVOPS_EMAIL"
  echo "Switched to Developer user: $DEVOPS_NAME"
}

# Function to set Freelancer user
set_freelancer() {
  git config --global user.name "$FREELANCER_NAME"
  git config --global user.email "$FREELANCER_EMAIL"
  echo "Switched to Freelancer user: $FREELANCER_NAME"
}

# Function to set Dummy User 1
set_dummy1() {
  git config --global user.name "$DUMMY1_NAME"
  git config --global user.email "$DUMMY1_EMAIL"
  echo "Switched to Dummy User 1: $DUMMY1_NAME"
}

# Function to set Dummy User 2
set_dummy2() {
  git config --global user.name "$DUMMY2_NAME"
  git config --global user.email "$DUMMY2_EMAIL"
  echo "Switched to Dummy User 2: $DUMMY2_NAME"
}

# Function to set Dummy User 3
set_dummy3() {
  git config --global user.name "$DUMMY3_NAME"
  git config --global user.email "$DUMMY3_EMAIL"
  echo "Switched to Dummy User 3: $DUMMY3_NAME"
}

# Switch based on the first argument
case "$1" in
  devops)
    set_devops
    ;;
  freelancer)
    set_freelancer
    ;;
  dummy1)
    set_dummy1
    ;;
  dummy2)
    set_dummy2
    ;;
  dummy3)
    set_dummy3
    ;;
  *)
    echo "Usage: git use devops | freelancer | dummy1 | dummy2 | dummy3"
    ;;
esac

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Save and exit the editor (CTRL+X, then press Y and Enter).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Make the Script Executable
&lt;/h4&gt;

&lt;p&gt;Run the following command to make the script executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x ~/git-use.sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Create the Git Alias for Easy Use
&lt;/h4&gt;

&lt;p&gt;To easily use the script with Git, you need to create an alias for it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open your global Git configuration file using the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global --edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add the following alias section to the config file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[alias]
  use = !sh ~/git-use.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Test the git use Command
&lt;/h4&gt;

&lt;p&gt;Now you can test the script by using the following commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To switch to the DevOps user:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git use devops
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To switch to the Freelancer user:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git use freelancer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By following these steps, you can easily switch between different Git users based on your use case. This solution is ideal for developers working on multiple projects with different identities (e.g., personal vs. freelance vs. other roles) and simplifies the management of Git configurations.&lt;/p&gt;

</description>
      <category>github</category>
      <category>githubtricks</category>
      <category>automation</category>
      <category>easeyourwork</category>
    </item>
  </channel>
</rss>
