How To: Have a nice Git configuration
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
anduser.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 likegit diff
.diff.mnemonicPrefix
: now,git diff
will tell you between what the diff is done. Instead ofa
andb
, it will sayc
for Commit,i
for Index (staging area) andw
for Working directory.log.abbrevCommit
: limits hash display at 7 characters ingit log
,git diff
, etc…alias.hist
: create an alias for a pretty nice log with graph and usefull informations. To show it, usegit hist
.
Remember
There is hundreds of configuration variables, I just speak about some usefull here. For more informations, seegit help config
or theCONFIGURATION
section ofgit 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.
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>