Monday, 21 December 2015

Git - Configuration & Aliases

$ git config allows to get & set configuration variables that controls how git looks and operates from system level to individual repository clone. The variables can be stored in 3 different locations.

1. /etc/gitconfig file: Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically. Attempt to access this file on windows resulted in following error.

$ git config --system --list
fatal: unable to read config file 'C:\Program Files\Git\mingw64/etc/gitconfig': No such file or directory

2. ~/.gitconfig or ~/.config/git/config file: Specific to your user. You can make Git read and write to this file specifically by passing the --global option.

3. config file in the Git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository.

Each level overrides the value of previous level, so values in .git/config trump those in /etc/gitconfig.

Set your Identity

Your identity will be used in commit messages. To set identity,
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

This will add following entry in ~/.gitconfig file.
[user]
        email = johndoe@example.com
        name = "John Doe"
Notice that user becomes section title and all the attribute values are added under user section.

Git will use this value from all repositories if it is not locally overridden.

Set Editor

$ git config --global core.editor vi

Checking the Settings

To view only local settings -
$ git config --local --list

To view global settings -
$ git config --global --list

To view system settings -
$ git config --system --list

To view all the settings merged into one with their final values -
$ git config --list

Get Help

To get help on any of the git commands -
$ git help <verb>
$ git <verb> --help
$ man git-<verb>

Set Alias

There are certain commands which are extensively used. They can be aliased as follows.
$ git config --global alias.st status

.. And then execute as -
$ git st

Following is a nice alias to set -
$ git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
$ git hist
* 3a86518 2015-12-20 | Initial Checkin (HEAD -> master, origin/master) [Sibtain]

You can setup following aliases.
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

Reference Link - http://githowto.com/aliases

No comments:

Post a Comment

Your comments are very much valuable for us. Thanks for giving your precious time.

Do you like this article?