Git Configuration
Git configuration is a convenient way to set up the global or local configuration for a git project.
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.
Create the author's email in the global configuration file
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"
@gmail.com"
Step 6 Check log history of git and it should show the Author as "ritika" and email as "ritika 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"
dev_ritika@kmit.com"
Step 6 Check log history of git and it should show the Author as "dev_ritika" and email as "git log
Comments
Post a Comment