Hello DevOps or DevSecOps team here in this post I would like to expose more details about how the Git configurations can be done and viewed and where it is going to stored as file.
Git Basic Configurations and scopes
Let's see what are options we have for "git config" command in a Linux system, here I've used Ubuntu Linux to execute all 'git config' commands.
git config scopes |
There are three different levels : local, global, system-level configuration values attributes defined in Git.
- System
- Global
- Local
System level config
Git allows us to define System wide configuration that means the configured values will be available for all users in the system and for every project repository as well.
# System level configurations will be stored in /etc/gitconfig file git config --system core.editor "vim" git config --system merge.tool "vimdiff"The execution of the commands
git config --global command example |
Global level config
Git configure values are defined at user level you can work on multiple repositories within the same user scope. If you define same values defined as in the system then user level values will be overrides.
git config --global alias.co checkout git config --global alias.graph log --oneline --all --graph --decorate git config --global alias.graph "log --oneline --all --graph --decorate" git config --global alias.st status git config --global alias.ci commit git config --global alias.br branch git config --global --list cat .gitconfigDefining Global level configuration and where it stores on hands-on:
git config --global scope |
Local (Repository) level config
The configurations made at the local level are more overridden capacity than other two scopes. This will be useful project wise repository uses these definitions.
Now we configure global level user settings are as follows:
mkdir gitdemo-project cd gitdemo-project/ git init git config --local user.name "BhavaniShekhar" git config --local user.email "bhavanishekhar@vybhava.com" git config --local --list git st cat .git/configLe'ts execute this above commands for local repository wise config
git config --local scope example |
Troubleshooting: Learn from the Mistakes
I've proceeded here and created a file named 'mytest.py' and entered the sample code:
# This is first testing python program print("Hello Git Learners!")
First file adding to index
git add mytest.py warning: LF will be replaced by CRLF in mytest.py. The file will have its original line endings in your working directory
Note We will discuss about CRLF issue in the 'Setting end line'.
At the time of committing the code found that mistake in the mail-id that 'devopshunger' given instead of 'devopshunter'. Learn from mistakes!
How to edit my git configuration value for user.email?
It will be the same command it will override to reset the value.
git config --global user.email 'gladiator@devopshunter.com'
Now new problem configuration is changed but my git log shows that old mailid! how to update that? We have option '--amend', where this option will help us to amend previous commit.
git commit --amend --reset-author [master 4ec5de9] initial commit for the git learn project 1 file changed, 3 insertions(+) create mode 100644 mytest.py
Unless you don't setup the global user config values you will be warned and automatically takes the operating system user and hostname as git user details. If you setup your customized user.name and user.email that will be used to commit the changes in the local and remote repo. When everyone go for look into "git log" it will show tracking history about who did the code changes and what and when it was done that change.
Verify the Configurations that you made to the global level.
git config --list |grep user user.name=devops.warrior user.email=gladiator@devopshunter.com
How to Setup line ending preferences in Windows?
This will be trick that you need to use for the GitOps to work better outputs.
For Mac/Unix/Linux platform users
git config --global core.autocrlf input git config --global core.safecrlf true
For Windows platform user
git config --global core.autocrlf true git config --global core.safecrlf true
Try this trick on your git bash.
No comments:
Post a Comment