4. Configuring User Name, E-mail and Default Editor in git for first time use

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

echo "Your configurations has been set for..."
git config --list
[bash] #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 user.name "$GIT_USERNAME" git config user.email "$GIT_USEREMAIL" echo -n "Which editor you want to use? (vim / emacs) " read usereditor git config $FORCE_UPDATE –global core.editor $usereditor [/bash]

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

Leave a Comment