-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitconfig
More file actions
498 lines (485 loc) · 35 KB
/
gitconfig
File metadata and controls
498 lines (485 loc) · 35 KB
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
[user]
name = Robert King
email = h.robert.king@mailinator.com
[push]
default = matching
[alias]
# displays changes in a branch
#
# Usage: git authored <commit> [<author>]
# Example: git authored
# git author 977de
# git author 977de "Robert King"
authored = "!f() { \
commit_id=\"$1\"; \
if [[ -z $2 ]]; then \
author=\"$(git config user.name)\"; \
else \
author=\"$1\"; \
fi; \
author=\"${author// /\\s}\"; \
if [[ -z $commit_id ]]; then \
gitlog=\"$(git log --pretty='%H' --author=$author)\"; \
else \
gitlog=\"$(git log --pretty='%H' --author=$author | grep $commit_id)\"; \
fi; \
changed=(); \
commits=(${gitlog//$'\n'/ }); \
for commit_key in \"${commits[@]}\"; \
do files=\"$(git show --oneline --name-only $commit_key | tail -n+2)\"; \
changed+=(${files}); \
done; \
files=(); \
files=\"$(echo ${changed[@]}|tr \" \" \"\n\"|sort|uniq)\"; \
echo \"${files[@]}\"; \
echo \"\"; \
};f"
# shows the date and time the specified branch was created in ISO format
# if no branch is specified, all branches are listed in alphabetical order
# unless the --by-date argument is passed, sorting branches in create-date
# order
#
# Usage: git created [--by-date] <branch>
# Example: git created
# git created issue-999
# git created --by-date
created = "!f() { \
shopt -s nocasematch; \
listing=\"$(git branch|sed s/^..//|sort)\"; \
branches=(${listing//$'\n'/ }); \
unsorted=(); \
for k in \"${branches[@]}\"; \
do verb=\"$(git log -1 --pretty=format:'%Cgreen%ci %Creset' $k)\"; \
unsorted+=(\"${verb} $k\"); \
done; \
sorted=(); \
for k in \"${unsorted[@]}\"; \
do smaller=(); \
larger=(); \
for el in \"${sorted[@]}\"; \
do if [[ $el < $k ]]; then \
smaller+=(\"$el\"); \
else \
larger+=(\"$el\"); \
fi; \
done; \
sorted=(); \
sorted+=(\"${smaller[@]}\"); \
sorted+=(\"$k\"); \
sorted+=(\"${larger[@]}\"); \
done; \
by_date=0; \
for k in \"$@\"; \
do if [[ $k =~ \\-by\\-date ]]; then \
by_date=1; \
else \
branch=\"$k\"; \
fi; \
done; \
if [[ by_date -eq 1 ]]; then \
for k in \"${sorted[@]}\"; \
do if [[ $k =~ $branch || -z $branch ]]; then \
echo $k; \
fi; \
done; \
else \
for k in \"${unsorted[@]}\"; \
do if [[ $k =~ $branch || -z $branch ]]; then \
echo $k; \
fi; \
done; \
fi; \
};f"
# identifies files modified in the specified commit
#
# Usage: git delta <commit>
# Example: git delta 977de
delta = "!f() { \
if [[ $# -lt 1 ]]; then \
echo \"\"; \
echo \"Identifies files changed in the specified commit\"; \
echo \"\"; \
echo \"Usage: git delta <commit-id>\"; \
echo \"Example: git delta 123abc\"; \
echo \"\"; \
exit -1; \
else \
echo \"\"; \
git show --pretty="format:" --name-only $1; \
echo \"\"; \
fi; \
};f"
# identifies whether or not the branch is in the remote repo
#
# Usage: git isremote <branch>
# Example: git isremote issue-999
isremote = "!f() { \
if [[ $# -lt 1 ]]; then \
echo \"\"; \
echo \"Identifies whether or not the branch is in the remote repo\"; \
echo \"\"; \
echo \"Usage: git isremote <branch> [<repo>]\"; \
echo \"Example: git isremote issue-branch-1 development\"; \
echo \"\"; \
exit -1; \
else \
if [[ -z $2 ]]; then \
r=\"origin\"; \
else \
r=\"$2\"; \
fi; \
b=\"$(git branch r | grep $r/$1 | sed 's/^ *//g' | sed 's/ *$//g')\"; \
if [[ -z $b ]]; then \
echo \"$1 is not in the remote repo '$r'\"; \
else \
echo \"$1 is in the remote repo ($b)\"; \
fi; \
fi; \
};f"
# makes a branch using a parent branch assuming remotes named 'upstream'
# and 'origin'
#
# Usage: git mkbranch <branch> <parent> [<upstream>] [<remote>]
# Example: git mkbranch issue-999 release-0.0.1
# git mkbranch issue-999 release-0.0.1 bugfix
mkbranch = "!f() { \
if [[ -z $1 ]]; then \
echo \"Branch name is missing\"; \
exit -1; \
elif [[ -z $2 ]]; then \
echo \"Parent branch is missing\"; \
exit -1; \
else \
b=\"$1\"; \
p=\"$2\"; \
if [[ -z $3 ]]; then \
u=\"upstream\"; \
else \
u=\"$3\"; \
fi; \
if [[ -z $4 ]]; then \
r=\"origin\"; \
else \
r=\"$4\"; \
fi; \
read -r -p \"Create $b as child of $u/$p? [y|N] \" response; \
if [[ $response =~ ^[yY] ]]; then \
git checkout -b $b $u/$p; \
if [[ $? == 0 ]]; then \
git pull; \
if ! [[ $r =~ ^local ]]; then \
git push $r $b; \
fi; \
else \
exit -1; \
fi; \
else \
echo \"Aborting\"; \
fi; \
fi; \
};f"
# identifies files modified in a branch
#
# Usage: git modified [<branch>] [<parent>]
# Example: git modified mybranch branch-parent
modified = "!f() { \
if [[ -z $1 ]]; then \
bn=\"$(git branch | grep \\* )\"; \
bn=\"${bn/* /}\"; \
else \
counter=0; \
bn=\"\"; \
branches=\"$(git branch)\"; \
branches=\"$(echo $branches|tr -d '\n')\"; \
branches=($branches); \
for branch in \"${branches[@]}\"; \
do if [[ $branch =~ $1 ]]; then \
bn=\"$branch\"; \
counter=$((counter + 1)); \
fi; \
done; \
if [[ -z $bn ]]; then \
echo \"\"; \
echo \"Error: Unable to find a matching branch\"; \
echo \"\"; \
exit -1; \
elif [ $counter -gt 1 ]; then \
echo \"\"; \
echo \"Error: Multiple branches match '$1'\"; \
echo \"\"; \
exit -1; \
fi; \
fi; \
if [[ -z $2 ]]; then \
p=\"$(git config --get branch.$bn.merge)\"; \
p=\"${p##*/}\"; \
else \
p=\"$2\"; \
fi; \
file_list=\"$(git diff --name-only $bn $p)\"; \
echo \"$file_list\"; \
};f"
# moves/renames a branch
#
# Usage: git mvbranch <from-branch> <to-branch> [<remote>]
# Example git mvbranch
mvbranch = "!f() { \
if [[ $# -lt 2 ]]; then \
echo \"Usage: git mvbranch <from-branch> <to-branch> [<remote>]\"; \
exit -1; \
else \
bn=\"\"; \
branches=\"$(git branch)\"; \
branches=\$({branches//$'\n'/ }); \
for branch in \"${branches[@]}\"; \
do if [[ $branch =~ $1 ]]; then \
bn=\"$branch\"; \
fi; \
done; \
if [[ -z $bn ]]; then \
echo \"\"; \
echo \"Unable to find a matching branch\"; \
echo \"\"; \
exit -1; \
fi; \
nb=\"$2\"; \
if [[ -z $3 ]]; then \
r=\"origin\"; \
else \
r=\"$3\"; \
fi; \
read -r -p \"Rename $bn to $nb? [y|N] \" response; \
if [[ $response =~ ^[yY] ]]; then \
b=\"$(git branch -r | grep $r/$bn | sed 's/^ *//g' | sed 's/ *$//g')\"; \
git branch -m $bn $nb; \
if ! [[ -z $b ]]; then \
read -r -p \"Rename remote $bn to $nb? [y|N] \" remote_response; \
if [[ $remote_response =~ ^[yY] ]]; then \
git push $r :$bn; \
fi; \
fi; \
git push --set-upstream $r $nb; \
else \
echo \"Aborting\"; \
fi; \
fi; \
};f"
# removes a branch
#
# Usage: git rmbranch <branch>
# Example: git rmbranch issue-999
rmbranch = "!f() { \
if [[ -z $1 ]]; then \
echo \"Branch name is missing\"; \
exit -1; \
else \
bn=\"\"; \
branches=\"$(git branch)\"; \
branches=\$({branches//$'\n'/ }); \
for branch in \"${branches[@]}\"; \
do if [[ $branch =~ $1 ]]; then \
bn=\"$branch\"; \
fi; \
done; \
if [[ -z $bn ]]; then \
echo \"\"; \
echo \"Unable to find a matching branch\"; \
echo \"\"; \
exit -1; \
fi; \
if [[ -z $2 ]]; then \
r=\"origin\"; \
else \
r=\"$2\"; \
fi; \
read -r -p \"Deleting $bn. Are you sure? [y|N] \" response; \
if [[ $response =~ ^[yY] ]]; then \
git checkout $bn; \
if [[ $? != 0 ]]; then exit -1; fi; \
git reset --hard; \
if [[ $? != 0 ]]; then exit -1; fi; \
git checkout master; \
if [[ $? != 0 ]]; then exit -1; fi; \
git branch -D $bn; \
fi; \
b=\"$(git branch -r | grep $r/$bn | sed 's/^ *//g' | sed 's/ *$//g')\"; \
if ! [[ -z $b ]]; then \
read -r -p \"Delete the remote branch? [y|N] \" response; \
if [[ $response =~ ^[yY] ]]; then \
git push $r :$bn; \
fi; \
fi; \
fi; \
};f"
# rolls back changes to the specified commit and optionally does a force push
#
# Usage: git rollback <commit>
# Example: git rollback 977de
rollback = "!f() { \
if [[ $# -lt 1 ]]; then \
echo \"\"; \
echo \"Rolls back a branch to the specified commit\"; \
echo \"\"; \
echo \"Usage: git rollback <commit-id> [<repo>]\"; \
echo \"Example: git rollback 24c51ade98e4f9cce2771b29a9a15973de308e53\"; \
echo \"\"; \
exit -1; \
else \
if [[ -z $2 ]]; then \
r=\"origin\"; \
else \
r=\"$2\"; \
fi; \
if [[ $1 =! ^[lL][aA][sS][tT] ]]; then \
git reset --hard HEAD^; \
else \
read -r -p \"Rolling back to $1. Are you sure? [y|N] \" response; \
if [[ $response =~ ^[yY] ]]; then \
git reset --hard $1; \
else \
echo \"Aborting\"; \
exit -1; \
fi; \
fi; \
echo \"!! THIS WILL DO A FORCE PUSH TO $r. YOU MUST CONFIRM. !!\"; \
read -r -p \"!! Confirm force push !! [y|N] \" ok; \
if [[ $ok =~ ^[yY] ]]; then \
git push $r HEAD --force; \
else \
echo \"Aborting\"; \
fi; \
fi; \
};f"
# unapplies a stash, if no stash index is specified, the last stash is
# 'unapplied'
#
# Usage: git unapply [<index>]
# Example: git unapply
# git unapply 3
unapply = "!f() { \
if [[ -z $1 ]]; then \
git stash show -p | git apply -R; \
else \
git stash show -p stash@{$1} | git apply -R; \
fi; \
};f"
# applies work previously stashed. if no stash index is specified, the last
# stash is applied and dropped
#
# Usage: git unstash [<index>]
# Example: git unstash
# git unstash 3
unstash = "!f() { \
if [[ -z $1 ]]; then \
git stash apply; \
git stash drop; \
else \
git stash apply stash@{$1}; \
git stash drop stash@{$1}; \
fi; \
};f"
# pushes the working branch to the remote
#
# Usage: git up [<remote>]
# Example: git up
# git up origin
up = "!f() { \
bn=\"$(git rev-parse --abbrev-ref HEAD)\"; \
if [[ -z $bn ]]; then \
echo \"Unable to determine working branch\"; \
else \
if [[ -z $1 ]]; then \
r=\"origin\"; \
else \
r=\"$1\"; \
fi; \
git push $r $bn; \
fi; \
};f"
# updates a branch to a new upstream
#
# Usage: git update <branch> <remote>
# Example: git update issue-999 upstream/release-0.1.0
update = "!f() { \
if [[ $# -lt 2 ]]; then \
echo \"\"; \
echo \"Update a branch to a new upstreamremote.\"; \
echo \"\"; \
echo \"Usage: git update <branch> <remote-branch>\"; \
echo \"Example: git update my-branch upstream/next-release-branch\"; \
echo \"\"; \
exit -1; \
else \
branch_name=\"\"; \
branches=\"$(git branch)\"; \
branches=(${branches//$'\n'/ }); \
for branch in \"${branches[@]}\"; \
do if [[ $branch =~ $1 ]]; then \
branch_name=\"$branch\"; \
fi; \
done; \
if [[ -z $branch_name ]]; then \
echo \"\"; \
echo \"Unable to find a matching branch\"; \
echo \"\"; \
exit -1; \
else \
git branch $branch_name -u $2; \
git pull; \
fi; \
fi; \
};f"
# switches branches given a partial branch name, includes stashing current work
#
# Usage: git workon <branch>
# Example: git workon 999
workon = "!f() { \
if [[ $# -lt 1 ]]; then \
echo \"\"; \
echo \"Switches branches\"; \
echo \"\"; \
echo \"Usage: git workon <defect>\"; \
echo \"Example: git workon Issue-9999\"; \
echo \"\"; \
exit -1; \
else \
branch_name=\"\"; \
branches=\"$(git branch)\"; \
branches=(${branches//$'\n'/ }); \
for branch in \"${branches[@]}\"; \
do if [[ $branch =~ $1 ]]; then \
branch_name=\"$branch\"; \
fi; \
done; \
if [[ -z $branch_name ]]; then \
echo \"\"; \
echo \"Unable to find a matching branch.\"; \
echo \"\"; \
exit -1; \
else \
unstaged=\"$(git status | grep 'Changes not staged for commit')\"; \
if [[ -n $unstaged ]]; then \
echo \"\"; \
echo \"Staged changes can be stashed; unstaged changes cannot.\"; \
echo \"You have unstaged changes that must be resolved.\"; \
echo \"\"; \
exit -1; \
fi; \
do_stash=\"$(git status | grep 'Changes to be committed')\"; \
if [[ -n $do_stash ]]; then \
git stash save; \
echo \"Changes stashed.\"; \
fi; \
git checkout $branch_name; \
stashes=\"$(git stash list | grep $branch_name)\"; \
if [[ $stashes =~ stash@\\{([0-9]+)\\} ]]; then \
stashes=\"${BASH_REMATCH[1]}\"; \
else \
stashes=\"\"; \
fi; \
if [[ -n $stashes ]]; then \
git unstash $stashes; \
fi; \
fi; \
fi; \
};f"