Home » Source Code Management ( SCM ) » Git » How to Configure Username, E-mail For First Time Git Setup ?

How to Configure Username, E-mail For First Time Git Setup ?

The first thing you should do when you install Git is, configure it to set your user name and email address. This is important because every Git commit uses this information to track who is the Author of this source code, what is his E-mail Id and date,time of when this code has been modified.

If you want to set the username and Email Id only for one git source and not for all the git’s available on your system, we can do the same by entering into the directory where git has been created and typing below commands,

 $ cd workspace
$ cd git_directory
$ git config user.name "YOUR_USERNAME"
$ git config user.email "YOUR_EMAIL_ID"
$ git config core.editor YOUR_PREFERRED_EDITOR

Above commands, sets the user name, email and editor for the git you are inside the directory.

Now, If you need to do this only once and available for all gits on the system, you can pass the –global option with above git config commands, like below,

$ git config --global user.name "$GIT_USERNAME"
$ git config --global user.email "$GIT_USEREMAIL"

You can configure the default text editor that will be used when Git needs you to type in a message. If not configured, Git uses your system’s default editor.

If you want to check your settings, you can use the git config –list command to list all the settings

git config --list

You can do all of this using our below script,

#!/bin/bash
#run it as, bash git-setup-configs.bash
#GIT_USERNAME="Linuxbee Developer"
#GIT_USEREMAIL="social@lynxbee.com"
#The first thing you should do when you install Git is to set your user name and email address.

#if you get any error related to updating user name etc if it was
# already updated in your machine, use FORCE_UPDATE="--replace-all"

#FORCE_UPDATE="--replace-all"
FORCE_UPDATE=""

echo -n "Enter your Name : "
read GIT_USERNAME

echo -n "Enter your Email : "
read GIT_USEREMAIL

git config $FORCE_UPDATE user.name "$GIT_USERNAME"
git config $FORCE_UPDATE user.email "$GIT_USEREMAIL"
# using --replace-all, to prevent any error if already configured,
# so this will override previous

echo -n "do you want to set this user credentials to all gits on this computer ? (yes / no) "
read userinput
if  [ $userinput == "yes" ]; then
	echo "setting userdetails as global"
	git config --global $FORCE_UPDATE user.name "$GIT_USERNAME"
	git config --global $FORCE_UPDATE user.email "$GIT_USEREMAIL"
fi

echo -n "Which editor you want to use? (vim / emacs) "
read usereditor
git config $FORCE_UPDATE --global core.editor $usereditor

echo "Your configurations has been set for..."
git config --list

You can use our script from GitHub at https://github.com/lynxbee/working-with-git/blob/master/git-setup-configs.bash


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment