ZANARDI Bruno

Software Developper

About
Resume

Git Blog

How To: Have a nice Git configuration

home next

related commands:
config

Here is a list of usefull commands to have a nice Git configuration. I’ll explain them after:

$ git config --global user.name <your_name>
$ git config --global user.email <your@email.com>
$ git config --global color.ui auto
$ git config --global status.showUntrackedFiles all
$ git config --global core.whitespace -trailing-space
$ git config --global diff.mnemonicPrefix true
$ git config --global log.abbrevCommit true
$ git config --global alias.hist 'log --pretty=format:\"%h - %d %s (%cr) <%an>\" --graph --date=relative --all'

Now, some explainations:

  • user.name and user.mail: you MUST set them. They will identify your commits.
  • color.ui: Git will use colors (as often as possible) in its messages. They will be more readable.
  • status.showUntrackedFiles: basically, git status will show untracked directories but won’t show files in it. With this option, it will only show untracked files.
  • core.whitespace: this option will force Git to ignore whitespaces related differences when using commands like git diff.
  • diff.mnemonicPrefix: now, git diff will tell you between what the diff is done. Instead of a and b, it will say c for Commit, i for Index (staging area) and w for Working directory.
  • log.abbrevCommit: limits hash display at 7 characters in git log, git diff, etc…
  • alias.hist: create an alias for a pretty nice log with graph and usefull informations. To show it, use git hist.

Remember
There is hundreds of configuration variables, I just speak about some usefull here. For more informations, see git help config or the CONFIGURATION section of git help <cmd> where <cmd> is the command you want to configure

As a gift, a better alias for log:

$ git config --global alias.hist 'log --graph --date=relative --all --pretty=format:\"%C(cyan)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset\"'

hist will show exact the same content than the previous, but colored.

home top next

Reminder

config

Add / modify a value to all users configuration

$ git config --system <var> <value>

Add / modify a value to user configuration

$ git config --global <var> <value>

Add / modify a value to repository configuration

$ git config --local <var> <value>

List all set variables

$ git config <cfg> -l

Remove a variable

$ git config <cfg> --unset <var>
home top next