-
Notifications
You must be signed in to change notification settings - Fork 6
/
.gitconfig
280 lines (250 loc) · 9.66 KB
/
.gitconfig
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
[user]
name = Todd Gamblin
email = tgamblin@llnl.gov
signingkey = C16729F1AACF66C6
[format]
signoff = true
[merge]
tool = opendiff
[color]
ui = auto
[core]
excludesfile = /Users/gamblin2/.gitignore_global
fsmonitor = true
untrackedcache = true
[pager]
# Preserve color and don't wrap lines in my fancy git logs (see below)
lg = less -FXRS
lga = less -FXRS
status = less -FXRS
# diff = $(dirname $(which git))/../share/git-core/contrib/diff-highlight/diff-highlight | less
[alias]
#
# Basic command aliases
#
st = status
ci = commit
co = checkout
tp = !"f() { \
cd -- ${GIT_PREFIX:-.} && \
mkdir -p $(dirname $1) && \
git touch $1; \
}; f"
unadd = reset HEAD
gr = !git grep
# pull develop
pd = fetch github develop:develop
# show all branches
br = branch --sort=-committerdate \
--format '%(HEAD) %(color:red)%(objectname:short)%(color:reset) %(if)%(HEAD)%(then)%(color:green)%(refname:short)%(color:reset)%(else)%(refname:short)%(end) - %(color:cyan)(%(committerdate:relative)%(if:notequals=Todd Gamblin)%(authorname)%(then), %(color:bold blue)by %(authorname)%(color:reset)%(color:cyan)%(end)) %(color:white)%(upstream:track)%(color:reset)%(color:reset)'
# show tracking branches
bt = branch --sort=-committerdate \
--format '%(HEAD) %(color:red)%(objectname:short)%(color:reset) %(if)%(HEAD)%(then)%(color:green)%(refname:short)%(color:reset)%(else)%(refname:short)%(end) - %(color:cyan)(%(committerdate:relative)%(if:notequals=Todd Gamblin)%(authorname)%(then), %(color:bold blue)by %(authorname)%(color:reset)%(color:cyan)%(end))%(color:reset)%(if)%(upstream)%(then) -> %(color:magenta)%(upstream:short) %(color:white)%(upstream:track)%(color:reset)%(end)'
# remove branches whose remote tracking branch is gone
bgone = !"f() { \
gone_branches=$(git branch \
--sort=-committerdate \
--format '%(refname:short) %(upstream:track)' \
| grep '\\[gone\\]' \
| cut -d' ' -f 1); \
for branch in $gone_branches; do \
if [ \"$1\" = --dry-run ]; then \
echo git branch -D $branch; \
else \
git branch -D $branch; \
fi; \
done; \
}; f"
# save and revert work on the tip of a branch
wip = commit -a -m WIP
unwip = !"f() { \
if [ $(git log -1 --format='%s') = WIP ]; then \
git reset HEAD^; \
else \
echo 'error:last commit is not WIP'; \
fi \
}; f"
#
# `git b` with no arguments shows branches ordered by commit date
# (most recent first)
#
# With arguments, it behaves like `git branch`
#
b = !"f() { \
if [ $# -ne 0 ]; then \
git branch \"$@\"; \
else \
git for-each-ref --sort=-committerdate refs/heads/ \
--format='%(HEAD) %(color:red)%(objectname:short)%(color:reset) %(if)%(HEAD)%(then)%(color:green)%(refname:short)%(color:reset)%(else)%(refname:short)%(end) - %(color:cyan)(%(committerdate:relative))%(color:reset)'; \
fi; \
}; f"
#
# Fancy logging: shows DAG in ascii with color alongside commits.
#
# - lg: Fancy log for current branch.
# - lga: Fancy log for all branches.
#
lg = log --oneline --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%aN <%ae>%Creset' --abbrev-commit
lgm = log --first-parent --oneline --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%aN>%Creset' --abbrev-commit
lgb = log --first-parent --oneline --color --graph --pretty=format:'%s' --abbrev-commit
lga = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%aN>%Creset' --abbrev-commit --branches --remotes --tags
#
# Make tarball out of the current head. Tarball and the contained
# directory will be named by the date and current HEAD's SHA.
#
tarball = !"f() { \
filename=\"$1\"; \
if [ \"x$filename\" = x ]; then \
name=\"$(basename $(git rev-parse --show-toplevel))\" && \
head=$(git log -1 --format=\"%h\" HEAD) && \
dstamp=$(git log -1 --format=\"%ci\" HEAD | awk '{print $1}') && \
filename=\"${name}-${dstamp}-${head}\"; \
fi; \
git archive --format=tar.gz --prefix=\"${filename}/\" HEAD -o ${filename}.tar.gz; \
}; f"
#
# These will purge branches that have already been merged.
#
# - bpurge: uses git branch -d
# - bpurge-force: uses git branch -D
#
bpurge = "!git branch --merged | \
grep -v '^\\*|master|develop|release' | \
xargs -n 1 git branch -d"
bpurge-force = "!git branch --merged | \
egrep -v '^\\*|master|develop|release' | \
xargs -n 1 git branch -D"
#
# Git Statistics
#
# - ghstats
# Show same statistics that GitHub's contributors page does:
# commits, insertions, & deletions, over the current branch.
#
# - lcontrib:
# Use `git blame` to sum up lines contributed by all users
# that are still in the current HEAD. This differs from
# ghstats becausae it shows only lines in the current
# snapshot, NOT insertions and deletions from all commits.
#
# - contrib:
# Show raw #commits made by users in current branch.
#
# All of the above aliases can take paths as arguments, e.g., if
# your repo has a subdirectory called "lib", you could do:
#
# git ghstats lib
#
# You can provide relative or absolute paths. You can also exclude
# paths from the statistics using git pathspecs, e.g. if you
# wanted to exclude contributions made in a directory containing
# external dependencies:
#
# # In the repository root
# git ghstats . ":(exclude)lib/external"
#
# NOTE: You cannot currently use relative paths with exclude.
# ONLY do this one in the repository root.
#
contrib = !"f() {\
printf '%7s %-30s %s\n' COMMITS NAME EMAIL && \
git log --branches --pretty=format:'%<(30)%aN %aE' HEAD -- $( \
for d in \"$@\"; do echo \"${GIT_PREFIX:-${d}}\"; done \
)| sort | uniq -c | sort -nr; \
}; f"
lcontrib = "!f() { \
for file in $( \
git ls-tree --name-only -r HEAD -- $( \
for d in \"$@\"; do echo \"${GIT_PREFIX:-${d}}\"; done \
) \
); do \
git blame -w --line-porcelain $file | \
perl -ne '\
if (/^[0-9a-f]{40} / .. /^filename /) { \
$author = $_ if (s/^author //); \
} else { \
print $author unless /^\\s*(\\#.*)?$/; \
}'; \
done | sort | uniq -c | sort -nr; \
}; f"
ghstats = "!f() { \
printf \"%-8s%-9s%-9s%-9s%s\\n\" '#' COMMITS INSERTED DELETED AUTHOR; \
git log --use-mailmap --shortstat HEAD -- $( \
for d in \"$@\"; do \
echo \"${GIT_PREFIX:-${d}}\"; \
done \
) | perl -e ' \
while (<>) { \
if (/^Author: (.*)$/) { \
$a = $1; \
$c{$a} = 0 unless defined $c{$a}; \
$i{$a}=0 unless defined $i{$a}; \
$d{$a}=0 unless defined $d{$a}; \
} \
if (/^ (\\d+) files? changed(?:, (\\d+) insertions?\\(\\+\\))?(?:, (\\d+) deletions?\\(\\-\\))?/) { \
$c{$a} += 1; \
$i{$a} += $2; \
$d{$a} += $3; \
} \
}; \
printf(\"%-9d%-9d%-9d%s\\n\", $c{$_}, $i{$_}, $d{$_}, $_) for (keys %i);' \
| sort -nr | nl -n ln -w 5; \
}; f"
closed = "!for br in $(git branch); do if git is-merged $br &>/dev/null; then echo $br; fi; done"
# get the github name of this repository by looking at all the github
# remotes and picking the most popular name there.
ghname = "!f() {\
git remote -v |\
perl -ne '\
if (s/.*github.com[:\\/]([^\\/]*)\\/([^\\s]*) \\(push\\)/\\2/) { s/\\.git$//; print; }'|\
sort |\
uniq |\
head -1;\
}; f"
# Add a remote for a github fork of this repository in a new org
ghadd = "!f() {\
name=$(git ghname) && \
git remote add $1 git@github.com:$1/$name.git; \
git fetch $1; \
}; f"
# Go to the github/gitlab page for this repo
go = "!f() {\
url=$(git remote -v | grep '^origin\\|^github\\|^gitlab' | \
sort -r | \
egrep -o 'git..b.com[:/][^/ ]+/[^/ ]+' | head -1 | \
perl -pe 's@(git..b\\.com).([^/ \\.]+)/([^/ \\.]+)(.git)?@https://\\1/\\2/\\3@' \
) && \
python -c \"import webbrowser; webbrowser.open('${url}')\"; \
}; f"
[push]
default = simple
[credential]
helper = cache --timeout=43200
[http]
postBuffer = 524288000
[difftool]
prompt = false
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
cmd = /Users/gamblin2/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
trustExitCode = true
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
path =
[rerere]
enabled = true
[rebase]
instructionFormat = (%an <%ae>) %s
autosquash = true
[tag]
forceSignAnnotated = true
[fetch]
prune = true
[pull]
ff = only
[init]
defaultBranch = main
[diff]
tool = opendiff
[commit]
gpgsign = true