GIT - configuration


Is it possible to use include statements in .gitconfig ?

Yes, this is possible since Git 1.7.10 :
	path = path/to/the/other/gitConfigurationFile
This comes with some instructions :
  • the expansion of $HOME is not supported
  • ~ is supported since Git
  • 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


	email	=
	name	= Thomas ANDERSON

	template = ~/.gitCommitTemplate

	# 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

	conflictStyle = diff3

	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

	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.

	branch	= auto
	diff	= auto
	status	= auto

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

	helper = cache --timeout=3600

Use a template for better commit messages

Good commit messages are important because we tend to use them to describe (which is exactly what git diff is for) instead of explaining why we made those changes, which can not be read in the code.
To keep this in mind at the time of writing a commit message, 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 :
      	template = /home/bob/.gitCommitTemplate
  4. Enjoy


.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

# 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)