Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 16, 2021 11:57 pm GMT

Git Config and Git Aliases

Hey Guys!! In this Blog I will tell you about git config command, Git aliases, which allow you to create shortcuts for frequently used Git operations. Becoming familiar with git config and the various Git configuration settings will help you create a powerful, customized Git workflow.
I have posted the video on Git Config and Git Aliases on my YouTube Channel so you can watch that Video for Detailed Explanation through video.
Link To Video - Git Config and Git Aliases

What is Git Config ?

The git config command is a convenience function that is used to set Git configuration values on a global or local project level. These configuration levels correspond to .gitconfig text files.
In one line - "The git config command is a function that sets configuration variables"

The git config levels and files

Mainly there are three config levels

--local
When no configuration option is passed git config writes to a local level, by default.The repository of the .git directory has a file that stores local configuration values.

--global
The application of the global level configuration includes the operating system user. Global configuration values can be found in a file placed in a user's home directory.

--system
The System-level configuration includes all users on an operating system and all repositories. System-level configuration is applied across an entire machine. System-level configuration file is located in a git config file of the system root path.

NOTE: the order of priority for configuration levels is: local, global, system. This means when looking for a configuration value, Git will start at the local level and bubble up to the system level.
git_cinfig

Configuring Name and Email in Git Bash :

Let's First check whether our name and email are set or not :

git config user.email  
git config user.name

If your Email and name are not set you can set them by:

git config user.email "[email protected]"
git config --global user.name "first_name last_name"

Color.Ui

Git comes with another property of providing color to the outputs. By default I think it is set to auto.
If your git color ui is not enabled you can enable it by the command :

git config --global color.ui true

To make it set to auto apply this command:

git config --global color.ui auto

For disabling all Git's colored terminal output you can do the following:

git config --global color.ui false

Git Aliases

Git Aliases are custom shortcuts that define which command will expand to longer or combined commands. Aliases save you the time and energy cost of typing frequently used commands. Git provides its own alias system.
And every developer want his code to be short and clear to make it understand properly and conserve his time so that he can make that time useful to develop other things.
Git aliases are stored in Git configuration files.

Example : You do git commit -m "new commit" but with git commit you can do it simply by git cm "new commit"

The general git config command used to configure aliases is:
aliases

NOTE: We will set aliases globally because we require alias to be set for our whole Operating System.

Now let's see some git alias:

$ git config --global alias.co checkout$ git config --global alias.br branch$ git config --global alias.ci commit$ git config --global alias.st status

Changing git aliases at any time :

You can Change, Delete or add new aliases by these ways:
Command on git Bash -
Changing or Deleting -

git config --global --unset alias.<alias>

Editing on Vim or VsCode Editors
Changing, Adding or Deleting -

vim ~/.gitconfig
code ~/.gitconfig

To See all your Global config file setups including email, name, color.ui, aliases and more use the command :

cat .gitconfig

shows all details

Summary

I hope this Blog was helpful in improving your Git workflow. If you have any queries or suggestions, lets discuss in the comment section.
If you all like the content and got to learn something new please give a and .
To learn more about Git, GitHub, Git Config or any code related stuff Please go to my YouTube Channel and subscribe if you want more of such learning.
Dedicated video link on this topic - Video Link

Thank You and Happy Learning!!


Original Link: https://dev.to/gaurav24072002/git-config-and-git-aliases-5f2g

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To