Followers

Git Configuration

 

Git configuration is a convenient way to set up the global or local configuration for a git project.

Whenever we create the project and store it in the local repo then we need to mention the author's name and email address, these can be stored in the configuration file which can be local or global.

Global configuration

A global configuration file is common for all the git projects which reside on the same local system. If there is no configuration defined on the local level then the global configuration is referred for git project settings. A file .gitconfig gets created under the user folder.

Example:- To Create a user name and email in the global configuration file.

Find the user's home directory.
    echo $HOME 
Create a global configuration file ( .gitconfig file under home directory) with below command and it will define an author with name devops    
    git config --global user.name devops 
    cat /root/.gitconfig
Create the author's email in the global configuration file
             git config --global user.email devops@gmail.com
               

With above command, a new section will be created in .gitconfig file

[user]

name = devops

email = devops@gmail.com

Case Study 1 -For Global Configuration

Ritika is a software developer and she works on a project (let's say MyProj) on her laptop and manages her project's repository using git. She wants to set up the Author and email of the project with her name and email address respectively so that when she commits the changes to the local repository then it should be recorded with her name and later she can push these changes to the global repository.

Solution

Step 1 To Initialize the git repository for the MyProj project (Consider MyProj is a directory and all the files in this directory are project files).

       cd MyProj
       git init

Step 2 Setup Author name and email on global level configuration(Check .gitconfig file for your reference after running below commands)

       git config --global user.name ritika
       git config --global user.email ritika@gmail.com

Step 3 create a project file say myfile_1.txt under MyProj Folder

       touch myfile_1.txt

Step 4 Check the git status of the file ( it should be untracked file)

       git status

Step 5 Commit the changes to local git repository.

       git add myfile_1.txt
       git commit -m "myfile_1.txt is added"

Step 6 Check log history of git and it should show the Author as "ritika" and email as "ritika@gmail.com"

       git log

Case Study 2 - For Local Configuration

Now Ritika has to do the development on a development server where multiple developers work on their projects. In this case, Ritika does not want to use git Global configuration instead of she wants to set the author name and email address in the local configuration file of the project so that if she pushes the changes to GitHub Repository then it should be recorded with her name.

Solution

Step 1 To Initialize the git repository for the LocalConfigProj project (Consider LocalConfigProj is a directory and all the files in this directory are project files).

       cd LocalConfigProj
       git init

Step 2 Setup Author name and email on local level configuration(Check .git/config file for your reference after running the below command)

       git config --local user.name dev_ritika
       git config --local user.email dev_ritika@kmit.com

Step 3 create a project file say myfile_1.txt under LocalConfigProj Folder

       touch myfile_1.txt

Step 4 Check the git status of the file ( it should be untracked file)

       git status

Step 5 Commit the changes to local git repository.

       git add myfile_1.txt
       git commit -m "myfile_1.txt is added"

Step 6 Check log history of git and it should show the Author as "dev_ritika" and email as "dev_ritika@kmit.com"

       git log

COMMENTS

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
static_page
DevOpsWorld: Git Configuration
Git Configuration
DevOpsWorld
https://www.devopsworld.co.in/p/git-configuration.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/p/git-configuration.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content