3 minute read

I was searching for inspiration for a good Git tutorial and I stumbled across a wonderful resource.

Sure, you can take a week off and read the official Git Book but I wanted to give a crash course where I work so it was a bit lengthy. Don’t get me wrong, the Git Book is wonderfully written and anyone serious about Git should read it at least diagonally. However, if you don’t feel it at the moment, head over at http://www.vogella.com/articles/Git/article.html

Also, here is my setup for gitconfig and gitignore. Just copy gitignore to /etc/gitignore – or ~/.gitignore and change the corresponding path.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# gitconfig
# http://blog.lavoie.sl/2012/10/git-tutorial-and-global-configs

[user]
	name = Sébastien Lavoie
	email = github@lavoie.sl

[color]
	diff = auto
	status = auto
	branch = auto
	interactive = auto
	ui = true
	pager = true
[color "branch"]
	current = yellow reverse
	local = yellow
	remote = green
[color "diff"]
	meta = yellow bold
	frag = magenta bold
	old = red bold
	new = green bold
[color "status"]
	added = yellow
	changed = green
	untracked = cyan

[core]
	editor = vi
	pager = less -FRSX
	whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol,space-before-tab
	excludesfile = /etc/gitignore
[apply]
	whitespace = fix

[alias]
	st = status
	ci = commit
	br = branch
	co = checkout
	d = diff
	dc = diff --cached
	dn = diff --name-status
	lg = log -p
	who = shortlog -s --
	w = whatchanged

	# Branch, push, set upstream
	brp = "!sh -c '[ $# = 1 ] && git checkout -b \"$1\" && git push -u origin \"$1\" || echo \"usage: git brp <new branch>\" >&2 && exit 1' -"

	lg = log --graph --pretty=format:'%Cred%h %C(yellow)%d %C(bold blue)<%an> %Cgreen(%cr) %n %Creset %s' --abbrev-commit --date=relative
	tree = "log --pretty=format:'%H%d: %s%n  %ad %n  %an (%ae)' --graph"
	forest = "log --pretty=format:'%H%d: %s%n  %ad %n  %an (%ae)' --graph --all"

	aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'
	alias = "!sh -c '[ $ # = 2 ] && git config --global alias.\"$1\" \"$2\" && exit 0 || echo \"usage: git alias <new alias> <original command>\" >&2 && exit 1' -"
	pp = !git pull && git push
	root = rev-parse --show-toplevel

	# Show files ignored by git:
	ign = ls-files -o -i --exclude-standard

	graphviz = "!f() { echo 'digraph git {' ; git log --pretty='format:  %h -> { %p }' \"$@\" | sed 's/[0-9a-f][0-9a-f]*/\"&\"/g' ; echo '}'; }; f"

	# show list of contributors in descending order by number of commits
	rank = shortlog -sn --no-merges

	# Search for a given string in all patches and print commit messages
	# example: search for any commit that adds or removes string "foobar"
	#     git searchcommits foobar
	# example: search commits for string "foobar" in directory src/lib
	#     git searchcommits foobar src/lib
	# example: search commits for "foobar", print full diff of commit with 1 line context
	#     git searchcommits foobar --pickaxe-all -U1 src/lib
	searchcommits = "!f() { query=\"$1\"; shift; git log -S\"$query\" \"$@\"; }; f \"$@\""

# http://twobitlabs.com/2011/08/install-diffmerge-git-mac-os-x/
[merge]
	tool = diffmerge
[mergetool "diffmerge"]
	cmd = "diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$(if test -f \"$BASE\"; then echo \"$BASE\"; else echo \"$LOCAL\"; fi)\" \"$REMOTE\""
	trustExitCode = true
[diff]
	tool = diffmerge
[difftool "diffmerge"]
	cmd = diffmerge \"$LOCAL\" \"$REMOTE\"

# http://stevenharman.net/git-pull-with-automatic-rebase
[branch]
	autosetuprebase = always

# http://pivotallabs.com/users/alex/blog/articles/883-git-config-push-default-matching
[push]
	default = matching
[mergetool]
	keepBackup = false
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# gitignore
# Temp and swap files
*~
*.swp
*.tmp

# Compiled source
*.com
*.class
*.dll
*.exe
*.o
*.so

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

View Gist

Tags:

Updated: