GIT - configuration

mail

Is it possible to use include statements in .gitconfig ?

Yes, this is possible since Git 1.7.10 :
[include]
	path = path/to/the/other/gitConfigurationFile
This comes with some instructions :
  • the expansion of $HOME is not supported
  • ~ is supported since Git 1.7.10.2
  • relative paths are relative to the file having the [include] statement
  • chaining [include]s is permitted
  • files not found are silently ignored. To make sure files were actually included, list all your git settings with git config --list
mail

.gitconfig

[user]
	email	= thomas.anderson@metacortex.com
	name	= Thomas ANDERSON


[commit]
	template = ~/.gitCommitTemplate


[diff]
	# Use better, descriptive initials (c, i, w) instead of a/b (source) :
	#	c : 'Commit' (most often: HEAD)
	#	i : 'Index' (aka: staging area)
	#	w : 'Working directory'
	mnemonicPrefix = true
	colorMoved = blocks


[alias]
	a	= add
	ap	= add --patch
	b	= branch
	co	= commit
	cane	= commit --amend --no-edit

	d	= diff			# highlight differences (at line level) with green/red and +/-
#	d	= diff --color-words	# highlight differences (at word level) with green/red but without +/-
					# NB : a 'word' is anything but whitespaces, so '--color-words'
					# may show nothing (ignoring whitespaces) while 'git status' list some changed files.

	ds	= diff --staged

	l	= ls-files
	l1	= log --oneline
	lf	= log --name-status
	lg	= log --all --graph --abbrev-commit --decorate --date=iso --format=format:'%C(yellow)%h%C(reset) %C(white)%s%C(reset) %C(blue)%an%C(reset)%C(bold yellow)%d%C(reset) %C(magenta)(%ad)%C(reset)'
	# (source)

	s	= status --untracked-files=no

	# show root dir of the current repository
	showrootdir	= rev-parse --show-toplevel
	srd		= showrootdir

	# count commits (yesterday / today / total) (inspired by)
	cc = "!f() { yesterday=$(date --date 'now -1 days' +'%a %b %-d ..:..:.. %Y'); today=$(date +'%a %b %-d ..:..:.. %Y'); nbCommitsYesterday=$(git log | grep -Ec \"$yesterday\"); nbCommitsToday=$(git log | grep -Ec \"$today\"); nbCommitsTotal=$(git rev-list HEAD --count); echo \"yesterday/today/total\n$nbCommitsYesterday/$nbCommitsToday/$nbCommitsTotal\" | column -s '/' -t; }; f"

	# squash commits, quicker than 'git rebase -i HEAD~n' (defaults to 'HEAD~2' if number not specified)
	squash = "!f() { git rebase -i HEAD~${1:-2}; }; f"
	sq	= squash


[pull]
	rebase = true	# turn "git pull" into "git pull --rebase" automatically
			# (i.e. "git pull" = "git fetch" + "git merge origin/master")
			# This produces a linear history (my commit came after all commits that were pushed before it,
			# instead of being developed in parallel). It makes history visualization much simpler and git bisect easier to see and understand.


[color]
	branch	= auto
	diff	= auto
	status	= auto


[color "diff"]	# available colors + attributes
	new = bold green
	old = bold red
	newMoved = dim green
	oldMoved = dim red


[credential]
	helper = cache --timeout=3600
mail

Use a template for better commit messages

Good commit messages are important because we tend to use them to describe To keep this in mind at the time of writing a commit messages, let's setup a template !
  1. create the template file : touch ~/.gitCommitTemplate
    You can name and store it the way you like : you'll have to specify its path+name to register it at the end .
  2. define your own template. For inspiration, here is my current template.
  3. register it :
    • git config --global commit.template ~/.gitCommitTemplate
    • OR: append to ~/.gitconfig :
      [commit]
      	template = /home/bob/.gitCommitTemplate
  4. Enjoy
mail

.gitignore

.gitignore is used to list : that we don't want Git to track.

Syntax rules :

Let's go with a commented example, since :
An example is worth 1000 words.
					blank lines can be used for readability
# exclude LaTeX .aux files		lines starting with a # are comments
*aux

# include ".*aux$" directories		I explain what I mean with regex, but these are not supported here 
!*aux/					! negates the corresponding rule (i.e. includes the matched files)

*log