DEV Community

Cover image for Git Config and Git Aliases
Gaurav Maheshwari
Gaurav Maheshwari

Posted on

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  
Enter fullscreen mode Exit fullscreen mode
git config user.name
Enter fullscreen mode Exit fullscreen mode

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

git config user.email "abc@gmail.com"
Enter fullscreen mode Exit fullscreen mode
git config --global user.name "first_name last_name"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To make it set to auto apply this command:

git config --global color.ui auto
Enter fullscreen mode Exit fullscreen mode

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

git config --global color.ui false
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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

vim ~/.gitconfig
Enter fullscreen mode Exit fullscreen mode
code ~/.gitconfig
Enter fullscreen mode Exit fullscreen mode

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

cat .gitconfig
Enter fullscreen mode Exit fullscreen mode

shows all details

Summary👉

I hope this Blog was helpful in improving your Git workflow. If you have any queries or suggestions, let’s 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😎!!

Top comments (2)

Collapse
 
melezhik profile image
Alexey Melezhik

Thanks for the post. You can also might take a look at some git related plugins at SparrowHub - sparrowhub.io/search?q=%5E%5Egit

Collapse
 
gaurav24072002 profile image
Gaurav Maheshwari

Thanks @melezhik for the suggestion.👍