-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitconfig
1919 lines (1713 loc) · 80.4 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
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# vim:tw=0:ts=2:sw=2:et:norl:ft=gitconfig
# Author: Landon Bouma (landonb @ retrosoft . com)
# Project: https://github.com/landonb/git-smart#💡
# License: MIT
# #######################################################################
# *** Overview ***
# #######################################################################
# USAGE: Read through the [alias]es defined below for a description of each.
# YOU/DEV: Put your user.* settings, private aliases, and whatever else you
# want in a separate, private config file, named .gitconfig.local, that's
# loaded last (at the end of this file, so it overrides anything herein).
# CONVENTION: Some commands work on branch(es) and remote(s) and will default
# to the following unless you pass args indicating otherwise
# (or unless the command otherwise deduces the remote name,
# e.g., by using the remote indicated by the tracking branch).
#
# - Remote names:
#
# 'origin' The default remote name assigned by `git clone`.
# Herein assumed to refer to repositories you control,
# e.g., if you fork a project, "origin" points to your
# fork on, say, GitHub. Or if you create a new project,
# "origin" refers to it.
# 'upstream' The remote name used for the main project repository,
# e.g., if you fork a project, the "upstream" remote
# points to the main project repository. The name,
# "upstream", is not codified by any tools, GitHub,
# etc., it's just what I've seen used a lot in online
# document/blog posts/Q&As, so I think it's well-known.
#
# 'proving' What I (lb) like to use instead of "origin", as in,
# where I prove my forked code works before submitting
# a pull request to the upstream project team.
# 'release' What I (lb) prefer to use instead of "upstream", as
# in, the "release" remote points to the main project
# repository that pushes out the actual releases. (And if
# I create a new project, I name its remote "release".)
# - I like to avoid the term "origin" to indicate that
# I'm deliberate about the remote name, so there should
# be no confusion about what the remote represents.
# 'starter' When I clone someone else's project, or if I fork a
# project, I name the project repository's remote "starter".
# That is, the "proving" and "release" remotes points to
# repositories under my control, but "starter" does not,
# and references the most-upstream remote.
# 'myclone' When I fork a project but do not plan to contribute to
# it, I'll name the remote "myclone". The name is arbitrary,
# but using a name other than "proving" or "release" ensures
# the git-my-merge-status command will not incorrectly
# diagnose the state of my local working tree.
#
# - Branch names:
#
# Most of the commands below work on the current branch, except
# for git-since, which assumes there's a "release" branch; and
# git-cleanup, which removes merged branches not identified as
# a "core" branch, one of: liminal|proving|release|private|main|trunk|develop.
#
# 'release' For any project I share/publish publicly, I always have
# at least a "release" branch. When I develop new code, I
# either commit directly to "release", or I'll use a feature
# branch (named something other than one of the core names)
# and later merge that work into release.
#
# 'private' For any project I do not publish but that's private to
# me, I generally have just one branch that I name "private",
# mostly to remind me (when I run `git branch`) that the
# project I'm working on is a private project.
#
# 'proving' For any public project under active develop, in addition
# to the "release" branch, I'll maintain a "proving" branch
# where I commit code under it's ready to be released. Other
# people might call the "proving" branch something different,
# such as "main", "trunk", or "develop", to name a few.
#
# 'main', 'trunk', 'develop'
# Similar in concept to 'proving'. While I don't use this
# branch name, it's recognized by at least a few commands,
# such as git-cleanup (below) and git-cleanbr (under bin/)
# that remove feature branches (but not any "core" branch).
#
# 'liminal' As Wikipedia states, "In anthropology, liminality is the
# quality of ambiguity or disorientation that occurs in the
# middle stage of a rite of passage." I use the branch name
# "liminal" on branches that I push remotely but that I later
# rebase. That is, other developers should not base their
# work on this branch, but I'll eventually rebase it before
# merging it to the "proving" branch. The "liminal" branch
# is essentially a feature branch, but one that I push to a
# remote so that it's backed up.
#
# 'wip/YYYY-MM-DD-*'
# Used for [w]ork [i]n [p]rogress branches. While none of
# the commands in git-smart are concerned with WIP branches,
# some spun-off projects do (such as git-my-merge-status),
# so it's worthy of note.
#
# 'tip/YYYY-MM-DD-abcdef01'
# Used for tipped forks, also not a concern of git-smart,
# but recognized by git-my-merge-status, so also so noted.
# A "tip" branch is a branch of a forked project that's
# ahead of the upstream's main development branch, but
# that you don't except/want to submit as a pull request.
# Think unique features you add that you're certain don't
# belong upstream, or that you don't think an upstream
# maintainer will accept. As such, you'll periodically
# rebase your changes atop the upstream remote branch,
# say, 'refs/remotes/release/release'. You'll probably
# also not have a local main development branch (i.e.,
# you'll delete the "release" branch after cloning your
# fork, and you'll change the default branch on GitHub
# before deleting the "release" branch from there as well).
# - Tipping is a way to fork a project, and to make some
# changes without submitting an upstream pull request,
# but also to not publish a divergent "release" branch
# that you'd have to force-push to keep up to date. By
# using the "tip/YYYY-MM-DD-abcdef01" naming scheme,
# any time the upstream branch changes, you create a
# new tip branch, rebase your work, and publish a new
# tip. Obviously, this might be tedious if the upstream
# branch changes frequently, but I find myself only doing
# this on mostly stable projects that I've forked and need
# to tweak (such as my
# https://github.com/hotoffthehamster/click-hotoffthehamster
# forked project). Also, by following this workflow and
# naming scheme, we're broadcasting better what's going
# on (and avoiding new DEVs being misled by a 'release'
# branch that doesn't match the upstream project's).
# #######################################################################
# *** "Engage Your Core" ***
# #######################################################################
[core]
# Configure the pager.
# - Re: Not using `most`, not `less`, for the pager, because:
# - Using `most` looks a lot like using `less`, but note that `most`
# does not map Vim keys like `less` does. One might say that `most`
# isn't quite more than `less` so much as it is just neither `less`
# nor more. (By which I mean, I prefer `less` because I can use the
# same keys that Vim uses to browse and search.)
# - One possible advantage with `most` is to call it with some options,
# e.g., use `+s +'/---'` to advance `most` to the first change in the
# diff (effectively just skipping the first two lines of the diff...).
# E.g.,
# pager = most +s +'/---'
# But, like I said, I'd rather have Vim-like search and navigation bindings.
# - Setting the pager configures `git diff|log|mergetool` to use `less`
# to display text.
# - Use `-R`, so `less` interprets ANSI color codes, otherwise they're
# shown raw, e.g., "[ESCapes234".
pager = less -R
# Configure the editor.
# - Similar to how Vim defers to another application for paging, Vim also
# defers to another application for editing, e.g., what's invoked when
# you run `git ci -v`, for one, or `git rebase -i ...`, for another.
# - Git defaults to using the (Bash) "EDITOR" environment variable to
# determine which application to run. So generally you don't need to
# specify it here, unless you want to do something special.
# - E.g., for a while, I had Vim startup issues when run from git, so
# I just made a Bash script that essentially called `vim --noplugin`,
# and then I wired it here, e.g.,
# editor = ~/.local/bin/git-vim
# or even just:
# editor = vim --noplugin
# but then I got off my tuchus and fixed my Vim scripts.
# So I'm not setting `editor` here.
# - You should rely on the EDITOR environ.
# SKIPPING:
# editor = ...
# Configure git's taste for whitespace.
# - I like a blank line at the end of every file. This ensures that when I
# jump the cursor to the end of a file, it then rests at the first column
# of a new line, as opposed to being placed in the last column of some
# unknown-length line of characters.
# - But git complains when you add files that have a trailing new line.
# So tell git not to worry or bark at you.
# - Ref:
# https://stackoverflow.com/questions/27059239/git-new-blank-line-at-eof
# - See also:
# whitespace = cr-at-eol
whitespace = -blank-at-eof
# #######################################################################
# *** git colorful ***
# #######################################################################
# - We could enable color one by one, e.g.:
#
# branch = auto
# diff = auto
# status = auto
# interactive = auto
#
# Or we could enable 'em all at once, e.g.:
#
# ui = auto
#
# - Instead of `auto`, we could use `always`, so that
# piping pipes colors, e.g.,
#
# git config color.ui always
# git log --stat | less # So colorful!
#
# But then -- *caveat* -- you'd want to disable color when parsing output,
# lest the color codes break your code, i.e., ruin string comparisons, etc.
# Which you could work around with a one-off config override, e.g.,
#
# git -c color.ui=off ...
#
# or by using the global no-color option:
#
# git --no-color ...
#
# but that's just too messy.
#
# Going with 'auto' seems like a happy place.
[color]
ui = auto
# 2020-02-09: I added these colors years ago. Source unknown.
# - But they've withstood the test of time. They look nice.
[color "branch"]
current = green bold
local = green
remote = red bold
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = green bold
changed = yellow bold
untracked = red
# #######################################################################
# *** advice ***
# #######################################################################
# "I'm all good, thanks."
#
# Quell Git advice, e.g.,
#
# $ git add
# Nothing specified, nothing added.
# hint: Maybe you wanted to say 'git add .'?
# hint: Turn this message off by running
# hint: "git config advice.addEmptyPathspec false"
[advice]
addEmptyPathspec = false
# #######################################################################
# *** diff ***
# #######################################################################
[diff]
# Use the 'minimal' diff algorithm to achieve desired diff behavior.
# - For example, in a reST file containing section headers, like "#######",
# I cut and pasted a big block of text, and the default greedy git diff
# algorithm, myers, shows the move as a bunch of small deletions and
# insertions. (But if you diff using `meld`, you see one big deletion
# and one big insertion.) We can use a different algorithm to make the
# diff easier to parse.
# - Choices:
# default aka "myers".
# minimal Spend extra time to ensure smallest possible diff produced.
# patience Use "patience diff" algorithm when generating patches.
# histogram This algorithm extends the patience algorithm to
# "support low-occurrence common elements".
algorithm = minimal
# Hide the path prefix from git-diff output.
# - If you'd like to be able to double-click and copy-paste from git-diff
# output, suppress the awkward "a/" and "b/" path prefixes.
# - I think these prefixes are holdovers from old SCMs. See:
# https://stackoverflow.com/questions/6764953/
# what-is-the-reason-for-the-a-b-prefixes-of-git-diff
noprefix = true
# NOTE: The diff.noprefix option does not apply to the 'a/' and 'b/'
# prefixes shown in interactive patch mode, i.e., on `git add -p`.
# - The `--no-prefix` option is documented in `git-diff --help`, but it's not
# found in `git-add --help`. (So I'm guessing there's no builtin mechanism.)
# - But don't fret! git-smart has the answer!
# - The `diff-filter-garden` script shows how to strip the 'a/' and 'b/'
# prefixes -- but it also adds a visual break between interactive patch
# hunks, which you may or may not like. So if you just want the prefix
# stripping, you'll have to pull it out yourself!
# - Look for and copy the interactive.diffFilter setting from the
# `.gitconfig.local.example` file to your own config to try it out.
# A more informative binary diff, how brilliant!
# - Found solution to more meaningful PDF diff at:
# https://superuser.com/questions/706042/how-can-i-diff-binary-files-in-git
# - See the `*.bin diff=bin`, etc., rules in ~/.config/git/attributes, and ref:
# man 5 gitattributes
[diff "bin"]
textconv = hexdump -v -C
[diff "pdf"]
textconv = pdfinfo
[diff "zip"]
textconv = unzip -v
# #######################################################################
# *** merge ***
# #######################################################################
# *** VIM-MERGETOOL
# (Skip this section unless you want to know all about vim-mergetool!)
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 2021-02-15: I tried using git-mergetool years ago, but it never stuck.
#
# - I didn't like that the default view (whether Vimdiff or meld) shows
# you three files, but that the automatically resolved hunks still show
# up in the diff (which makes finding and resolving the unresolved
# conflicts more difficult, and less obvious). So it felt like I was
# doing *more* work than if I just edited the conflict file directly
# (and removed the <<< === >>> conflict delimiters manually, too).
#
# - E.g., you'll see the "ours" version (mainline branch) on the left,
# and the "theirs" version on the right (e.g., your feature branch),
# and the merged result in the middle.
#
# - But, unfortunately, the merged result highlights hunks for conflicts
# that Git has already resolved, because those hunks still differ from
# either or both the files on the left and right. That's just how such
# a three-way works out!
#
# - To see for yourself: `git mergetool --tool=meld`.
#
# But today I finally dug a little deeper, and I found the perfect solution!
#
# - Check out vim-mergetool, which solves the problem by not bothering with
# the $LOCAL or $REMOTE versions. Rather, it uses the conflict file, which
# git-rebase leaves for you to fix, and makes a copy. Then, it removes the
# "their" hunks from the first file, and removes the "our" hunks from the
# second, copied, file; and also the <<< === >>> delimiters from both.
# Finally, it shows you the diff between those two files, with the first,
# editable "ours" file on the left, and the unmodifiable "theirs" version
# on the right. How simple is that, and how perfect! You only see the
# unresolved conflicts, and you don't have to bother with the delimiters,
# either.
#
# - See next for the vim-mergetool config, followed by discussion of the
# other mergetools, and finally, after that, more about (a lot more about)
# vim-mergetool usage (though not as long as the vim-mergetool README! =⟩
# (as if I'm one to talk!)).
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# You'll need vim-mergetool for the following settings:
#
# https://github.com/samoshkin/vim-mergetool
#
# Oh, and you'll need to use Vim. And I realize this ~/.gitconfig
# is generally editor-agnostic, but not for this setting!
# PRIMARY USAGE: `git mergetool`
[merge]
tool = vim_mergetool
conflictstyle = diff3
[mergetool "vim_mergetool"]
cmd = vim -f -c "MergetoolStart" "$MERGED" "$BASE" "$LOCAL" "$REMOTE"
# "When trustExitCode = false, checks if MERGED file was modified.
# When trustExitCode = true, checks exit code of merge tool process."
trustExitCode = true
[mergetool]
# Tell `git mergetool` to remove its intermediate files when finished.
keepBackup = false
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# *** Other mergetool tools.
# Some other merge tools that I demoed:
#
# [merge]
# tool = meld
#
# [merge]
# tool = vimdiff
# conflictstyle = diff3
#
# # https://github.com/tpope/vim-fugitive
# [merge]
# tool = fugitive
# conflictstyle = merge
#
# # "A better vimdiff mergetool for Git" circa 2012.
# # See: git-smart/bin/diffconflicts
# [merge]
# tool = diffconflicts
# There are two configurations that make the most sense with meld:
# [mergetool "meld"]
# cmd = meld "$LOCAL" "$BASE" "$REMOTE" --output "$MERGED"
# cmd = meld "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED"
# The second one, using $MERGED, is nice because it contains resolved
# conflicts that Git could figure out automatically. But that resolved
# code still diffs against either the $LOCAL or $REMOTE. As such, it's
# not exactly obvious when you're done, e.g., you won't end up with all
# three files in meld looking the same and not having any conflicts.
# Instead, you'll have to manually inspect all the diffs, decide that
# you're done and there's nothing more to edit, and then save and quit.
# The vimdiff tool gives a similar experience to meld in terms of what you
# see, and needing to mentally parse conflicts Git has already resolved.
# [mergetool "vimdiff"]
# cmd = vimdiff --noplugin "$LOCAL" "$MERGED" "$REMOTE"
# vim-fugitive can also mergetool (what can't it do! love that plug). But
# it suffers from same issues as `meld` and `vimdiff`, and shows you the
# automatically resolved conflicts mixed in with those that are unresolved.
# - See this post for more help:
# https://vi.stackexchange.com/questions/3985/git-mergetool-vimdiff-command
# The basic suggestion is to call Gdiffsplit when Vim starts, e.g.,:
# cmd = vim "+Gdiffsplit" $MERGED
# but I like also calling `Git mergetool`.
# Consider:
# [mergetool "fugitive"]
# cmd = vim "+Gdiffsplit" "+'Git mergetool'" $MERGED
# - Hints:
# - The + is like -c, and runs the command.
# - The `Gdiff[split]` (from vim-fugitive) starts the diff.
# - The `Git mergetool` (from vim-fugitive) populates quickfix with conflicts.
# - You'll see all the conflicts, including what Git has already resolved.
# - You can navigate with vim-unimpaired's `[Q` to go to first quickfix item.
# (I expected `[q` to also work, but alas, not for me (though maybe my fault)).
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# *** vim-mergetool in-depth.
# *** STARTING MERGETOOL
#
# If you've rebased and have conflicts, you can start from a terminal:
#
# git mergetool
#
# Alternatively, open a file that has conflicts and run vim-mergetool:
#
# :MergetoolStart
# *** RUNTIME USAGE
#
# - You can still run `:Git mergetool` (from vim-fugitive) if you want
# to see conflicts in quickfix, but `:MergetoolStart` already folds
# the file and shows only the remaining, unresolved conflicts.
#
# - You can use [c and ]c to jump between conflicts.
#
# - If you run `:Git mergetool`, [Q and ]Q work (and maybe [q and ]q ?).
#
# - The right-hand side is the "theirs" commit, aka your feature branch.
#
# - The left-hand side is the "ours" commit, aka the mainline (e.g., if
# you had called `git rebase upstream/develop`, then 'upstream/develop').
#
# - The right-hand side is read-only, so of the two built-in Vimdiff
# commands, `:diffget` and `:diffput`, you can only `:diffget` into
# the left-hand window, where has the focus to start.
#
# - Type `do` to get the diff chunk from the right-hand side. (Think
# mnemonic *diff obtain* (because `dg` is used by another command.)
#
# - If you happen to move the cursor to the right-hand side,
# use `dp` to *put* a diff chunk into the left-hand buffer.
# *** FINISHING MERGETOOL
# - You can `:MergetoolStop` when finished, and you'll be prompted
# to save changes or not. Answer yes and mergetool will accept
# your changes and stage the file. Or answer no and mergetool
# will revert the file, so that it includes the original
# unresolved changes (both sides' hunks and hunk delimiters).
#
# If you just want to save and have the file staged, you can
# skip `:MergetoolStop` and just write the left-hand file
# and quit, and mergetool will silently process the file.
#
# - If you realize you made a mistake after saving or otherwise
# telling mergetool to accept the changes, you can revert the
# file using the checkout command, so you can merge again. E.g.,
#
# git checkout -m -- {file}
#
# The -m option will unstage the file and revert it to the
# unresolved state with the unresolved hunks. (Or you might
# be able to `git rebase --abort` and start the rebase over,
# but `git co -m {file}` is more to the point.)
# *** HOW MERGETOOL PREPS
# - Note that the left-hand buffer is the original source file (that will
# be added to staging) and is not a copy like the right-hand buffer. So
# once :MergetoolStart has started and you're looking at the diff, the
# file is already changed.
#
# - As such, if you undo (e.g., press Ctrl-z) in the original file
# buffer, you will revert the changes that vim-mergetool made, and
# the file will be its original self, with both the "our" and "theirs"
# hunks, and with the <<< === >>> delimiters. Just like Vim left it
# after the rebase.
#
# - But if you start the merge, then save and exit immediately without
# editing, you'll effectively have accepted all the "our" changes,
# and ignored all the "theirs".
#
# - Or, you can use `:MergetoolStop`, which will ask if the edit was a
# success, and you can answer "no" to revert the file, or "yes" to
# add the file to staging (and then you can continue the rebase,
# e.g., run `git rebase --continue`, perhaps).
# *** FOLDING REMINDER
# - Be aware that you might want to expand folds (zR) while diffing,
# especially after editing, as changes you make might be clipped
# or hidden by a fold.
# *** QUITING REMINDER
# - You can quit quickly by saving the file, and then using `:qa`
# to close all windows and quit Vim.
#
# - Or, to not save, `:qa!` quits all windows and Vim, NQA.
#
# You can also use `ZQ` to quickly close and quit each window
# individually.
#
# (The author reminds themselves this because they mostly use
# non-standard <Alt-f e> and <Alt-f x> mappings to close all
# files and quit Vim (remnants of my Windows days, what can
# I say). And while I use `:q` or `ZZ` aplenty, I cannot say
# the same for `:qa` or `ZQ`.)
# *** MERGING *BOTH* HUNKS
# - Note that Vim has not plumbed an "accept both ours and theirs"
# option. I guess because it's rare? Though I think I've combined
# quite a few diff hunks in my devtime. Seems like it'd be useful.
#
# - To combine hunks, there are two approaches I find the fastest:
#
# - One option is to copy the left hand hunk, and then obtain the
# right-hand hunk (which overwrites the left-side), and paste.
#
# - Another option is to use undo to revert the vim-mergetool
# edits to the left-hand buffer, and then edit manually,
# possibly using \dx (custom mapping; or see the regex below)
# to remove the <<< === >>>s.
#
# - Approach #1: Yank, Obtain, Put:
#
# - Manually copy the hunk on the left, then press `do` to
# 'obtain' the other hunk. Then paste what you had just
# copied. This will also have removed the <<< === >>>
# delimiters.
#
# - To copy, probably count lines, then with cursor on the
# first line (in any column), type number of lines minus
# one (because the first line is inherently included), press
# `y`, and then either Down arrow or `j`. E.g., if the "ours"
# hunk is 5 lines, press `4yj`, then `do`, then `p` to put
# the yanked hunk.
#
# - Approach #2: Manually Edit:
#
# - You could use the undo trick after starting the vim-mergetool
# to bring back the conflict hunks. But it's probably easier to
# just edit the file normally, and to use a regex substitute to
# find conflicts to edit and to remove the <<< === >>> delimiters.
#
# - Using the following :global command removes all conflict
# delimiters (the :g will run `d` on all matching lines):
#
# :g/^<\{7}\|^|\{7}\|^=\{7}\|^>\{7}/d
#
# - Thanks to tecfu for that command!:
# https://github.com/tpope/vim-fugitive/issues/1022
#
# - Alternatively, you can run the substitute command
# to the same effect:
#
# :.,$s/^\(<\{7}\|^|\{7}\|^=\{7}\|^>\{7}\).*\n//g
#
# - Or, if you want to be prompted for each match, run:
#
# :.,$s/^\(<\{7}\|^|\{7}\|^=\{7}\|^>\{7}\).*\n//gc
#
# - I like the confirmational substitute command (the last
# one) so much that I made a home for it at `\dx`, e.g.,:
#
# autocmd DiffUpdated * if &diff | nnoremap <leader>dx
# \ :.,$s/^\(<\{7}\\|^\|\{7}\\|^=\{7}\\|^>\{7}\).*\n//gc<CR>
#
# - Then, e.g., if I started :MergetoolStart but see that I need
# to manually combine hunks, I could Ctrl-z to undo the initial
# merge step, and then I'd press \dx to jump to and remove each
# set of hunk delimiters, editing and resolving each pair of
# conflicting hunks along the way.
# - And that's `git mergetool` using `vim-mergetool` explained in 300 lines!
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# #######################################################################
# *** Ever-expanding Git Aliases Collection ***
# #######################################################################
# NOTE: The aliases are split across multiple groups listed below,
# hopefully to make the remainder of the file easier to read
# and maintain.
# NOTE: The only way to pass a global option to git is to shell out. AFAIK.
#
# So, e.g., instead of a simple alias such as:
#
# br = branch
#
# You'll see a slightly more complicated alias, e.g.,
#
# br = !git --no-pager branch
# TRICK: You can wrap shell code in an anonymous Bash function
# when you need to shell out, to have access to, well,
# at least the 'local' function (which can only be used
# in functions).
# - I read that you need to use an anonymous function to
# access command line variables and shell expansion.
# But I have aliases that shell out without a function
# wrapper, and they access numbered arguments
# ($1, $2, etc.) just fine.
# - E.g., it's the difference between writing this:
# my-alias = ! echo Hello
# and this:
# my-alias = "! f() { echo Hello; }; f"
# but not this (syntax error without quotes):
# my-alias = ! f() { echo Hello; }; f
# - Here's the article, which is good in its own right:
# https://www.atlassian.com/blog/git/advanced-git-aliases
# - Nonetheless, you'll see some shell code below wrapped in a
# function, and some code not. Just kinda depends.
# - Oh! I think unwrapped functions get arguments at the end, always,
# e.g., given the alias
# view = !echo \"FOO $@ BAZ\"
# then
# $ git view bar
# FOO bar BAZ bar
# So use the wrapper when necessary, e.g.,
# view = "! f() { echo \"FOO $@ BAZ\"; }; f"
# then it works more like one might expect:
# $ git view bar
# FOO bar BAZ
#
# NOTE: Shell code is run by POSIX (e.g., dash), not Bash, so
# avoid constructs such as [[ ]] unless you invoke Bash.
# - E.g., this is wrong:
# test1 = "! f() { [[ -z \"$1\" ]] && echo 'Z!' || echo 'n.'; }; f"
# Because it won't be run by Bash, and will throw an error, e.g.,
# $ git test1 "sdff"
# f() { [[ -z "$1" ]] && echo 'Z!' || echo 'n.'; }; f: 1:
# f() { [[ -z "$1" ]] && echo 'Z!' || echo 'n.'; }; f: [[: not found
# n.
# But you could instead shell out your shell code to Bash, e.g.,
# test2 = ! "/usr/bin/env bash -c \"f () { [[ -z \\\"$1\\\" ]] && echo Z || echo n; }; f\""
# or you could just rewrite it to be POSIX-compliant, e.g.,
# test3 = "! f() { [ -z \"$1\" ] && echo 'Z!' || echo 'n.'; }; f"
#
# NOTE: One final shell code note: You need to \-delimit line breaks;
# and you need to use a semicolon after each line (i.e., you
# cannot rely on newlines to signal the parser what's what).
# NOTE: Within each [alias] section, I've arranged my My Most Popular Git
# Aliases up top (those that I use the most), above a mini-ruler:
#
# # -------
# #######################################################################
# *** Branch Command Aliases ***
# #######################################################################
[alias]
br = !git --no-pager branch
# If you don't want coloration/coloring, and if you don't want the ` *`
# before the current branch, or ` ` before other branches, try:
# br = !git --no-pager branch --format='%(refname:short)'
# Years later: There's no `git b`, so why not print branch list,
# at least until a better `git b` emerges.
b = br
# - Use `git brs` to show all branches, including remote branches.
# - git-brs is inherently aliased because found on PATH.
# brs = !${GITSMART_BIN:-${HOME}/.local/bin}/git-brs \"$@\"
# -------
# Bro!
bro = "! f () { \
local tracking_br_rem tracking_remote; \
tracking_br_rem=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}); \
if [ $? -ne 0 ]; then \
>&2 printf '%s\\n' 'ERROR: Set tracking branch to use this command'; \
return 1; \
fi; \
tracking_remote=$( \
printf '%s' \"${tracking_br_rem}\" \
| /usr/bin/env sed -e 's#/.*$##' \
); \
\
printf '\\n'; \
printf '%b\\n' \"\\\\e[31mLocal branches\\\\e[0m\"; \
printf '%b\\n' \"\\\\e[31m--------------\\\\e[0m\"; \
git --no-pager branch -vv; \
printf '\\n'; \
printf '%b\\n' \"\\\\e[31mRemote branches (on '${tracking_remote}')\\\\e[0m\"; \
printf '%b\\n' \"\\\\e[31m---------------\\\\e[0m\"; \
git --no-pager ls-remote --heads ${tracking_remote} \
| /usr/bin/env sed 's?.*refs/heads/??' \
| /usr/bin/env sed -e \"s/^/\\ \\ /\" && \
printf '\\n'; \
}; f"
brs-all = !git --no-pager branch -avv
bra = !git --no-pager branch -avv
# Delete merged branches except any conventionally-named branch (e.g., the
# main development branch, what I call "proving" or others might call "main";
# the release branch, often called "release"; or a "private" branch, which is
# the branch label I use in private repositories I don't publish), and not
# the current branch, either.
# https://gist.github.com/jantimon/5b9fd9330f38d076a374c03fcbb788e1
# (jantimon/{} is technically not licensed: No license info.)
cleanup = "! f () { \
local tracking_br_rem tracking_remote; \
tracking_br_rem=$(git rev-parse --abbrev-ref --symbolic-full-name @{u}); \
if [ $? -ne 0 ]; then \
>&2 echo 'ERROR: Set tracking branch to use this command'; \
return 1; \
fi; \
tracking_remote=$(printf '%s' \"${tracking_br_rem}\" | /bin/sed -e 's#/.*$##'); \
\
git remote prune ${tracking_remote} && \
git branch --no-color --merged \
| egrep -v '(^\\*liminal|proving|release|private|main|trunk|develop)' \
| xargs git branch -d; \
}; f"
# Show the current branch name.
# (I added this alias years ago, but I hardly use it.
# - I usually check for the branch name using `git br`, unless I need to
# script it, and then I just call rev-parse directly.
# - I would have guessed that 'br' would be faster to type the 'cur',
# but they're about the same.
# - I think that `git br` is more versatile -- in addition to seeing what
# branch the tree is on, it also reminds me of what other branches exist.
# - The only reason I see to keep this alias is as a rev-parse usage example.)
# Weird: git rev-parse defaults --abbrev-ref per core.warnAmbiguousRefs, but
# rev-parse --abbrev-ref HEAD
# on Linux returns the --abbrev-ref=loose form, e.g., "my_branch", but
# on macOS it runs like --abbrev-ref=strict, e.g., "heads/my_branch".
# We want to be consistent, and to show the simpler name.
# 2022-10-05: This is poorly-named. I didn't recall this existed...
cur = rev-parse --abbrev-ref=loose HEAD
# 2022-10-05: Until I devise a better name, perhaps a TAB-completion reminder:
cur-br = rev-parse --abbrev-ref=loose HEAD
# FIXME/2022-10-05 20:07: Find a better alias, and consolidate previous 2 commands.
# -------
# - Use `git-cleanbr` to delete a branch locally and on the remote,
# after switching to 'develop' or another branch.
# - git-cleanbr is inherently aliased because found on PATH.
# cleanbr = !${GITSMART_BIN:-${HOME}/.local/bin}/git-cleanbr \"$@\"
# - Use `git-cob` to checkout a branch from an existing remote for which
# there is no local tracking branch, but for which there are multiple
# remotes with the same-named branch, and you cannot simply
# `git checkout <branch>` but have to be remote-specific.
# - git-cob is inherently aliased because found on PATH.
# cob = !${GITSMART_BIN:-${HOME}/.local/bin}/git-cob \"$@\"
# - Use `git-coc` to create a new branch, switch to it, and push it.
# - NOTE: I tried doing this inline, e.g.,
# coc = !git branch ${1} && git checkout ${1} && git push ${2:-origin} ${1} -u
# but git puts the args after the command, so the git push ends up looking like:
# git push ${2:-origin} ${1} -u ${1}
# which obviously fails. So shell out!
# - git-coc is inherently aliased because found on PATH.
# coc = !${GITSMART_BIN:-${HOME}/.local/bin}/git-coc \"$@\"
# - Delete branches that are "gone" on the remote.
# - You can find tracking branches with missing remote branches via:
# git branch -vv --no-color | grep ': gone]'
# and then you can big-D delete them thusly:
# git branch -D <branch>
# - git-gone is inherently aliased because found on PATH.
# gone = !${GITSMART_BIN:-${HOME}/.local/bin}/git-gone \"$@\"
# -------
# Upstream branch name. From:
# https://gist.github.com/pksunkara/988716#file-config-L86
# (pksunkara/988716 is technically not licensed: No license info.)
#
# SAVVY/2024-03-28: The git-rev-parse error message varies.
# - If there's no upstream configured, it'll print:
# fatal: no upstream configured for branch 'liminal'
# - But if the upstream is no longer valid, e.g., deleted branch, prints:
# @{u}
# fatal: ambiguous argument '@{u}': unknown revision or path not in the working tree.
# Use '--' to separate paths from revisions, like this:
# 'git <command> [<revision>...] -- [<file>...]'
# In which case set a new upstream or run `git branch --unset-upstream`.
# - If you really need to know the value, look in the config:
# git config branch.<name>.merge
# git config branch.<name>.remote
upstream = !git rev-parse --abbrev-ref --symbolic-full-name "@{u}"
# Number of commits ahead or behind upstream branch. From:
# https://gist.github.com/pksunkara/988716#file-config-L260-L261
ahead = !git rev-list --right-only --count $(git upstream)...HEAD
behind = !git rev-list --left-only --count $(git upstream)...HEAD
# #######################################################################
# *** Logging Aliases ***
# #######################################################################
# A few of the --pretty git log format options:
#
# %Cred red text
# %C(cyan) Choose from: (normal, black, red, green, yellow, blue, magenta, cyan and white)
# %h abbreviated commit hash
# %Creset reset text color
# %x0 print a byte from hex code (09: \t)
# %an author name
# %x09 TAB
# %ad author date (format respects --date= option)
# %x09 TAB
# %d ref names, like the --decorate option of git-log(1)
# %s subject
# %<(<N>[,trunc|ltrunc|mtrunc]) make the next placeholder take at least N columns...
# * 79c812f My Name Fri Mar 1q0 17:05:27 2017 Update README.
# * 2deef48 My Name Thu Mar 9 13:02:57 2017 Fix something.
# %<(24) is 24 chars for the "Fri Mar 10 17:05:27 2017" date. %>(24) to right justify.
# If you add a ` ` (space) after % of a placeholder, a space is inserted immediately
# before the expansion if and only if the placeholder expands to a non-empty string.
[alias]
# Use `git l` to show the latest log message.
# - (I tried other, longer names, such as `last`, `l1`, and `l`.
# But I like 'l' the best.
# - I like 'last' because it's descriptive, and the user probably doesn't
# have to guess what it does -- but it's annoying to type an 'a' after
# an 'l' (such a stretch across the keyboard!).
# - I like 'l1' because it's short, and it has a good pneumonic --
# 1 log record, or 'l1' (well, '1l', I suppose, but whatever).
# - And I like 'l' because it's also short -- but I don't normally like
# single character abbreviations, because it makes searching more
# difficult (there are usually tons of false-positives to sift through).
# Also, I don't like to use a coveted single character abbreviation
# unless I think it'll be well-used.
# - In this case, with 'l', I do like the single character -- it's quick
# to type, and it's not like this single character appears any place
# other then here (so there's no grep-pollution to worry about). Also,
# I can also use the pneumonic of wanting one log record: And what 1
# character does the word 'log' start with? It's an 'l'! Finally, I
# think I will use this option frequently (I've already started),
# so let's go ahead and use up a single character alias! Worth it!!)
# l = !git --no-pager log -1
l = "! f() { git --no-pager log -${1:-1}; }; f"
l1 = "! f() { git --no-pager log -1; }; f"
l2 = "! f() { git --no-pager log -2; }; f"
l3 = "! f() { git --no-pager log -3; }; f"
l4 = "! f() { git --no-pager log -4; }; f"
l5 = "! f() { git --no-pager log -5; }; f"
l6 = "! f() { git --no-pager log -6; }; f"
l7 = "! f() { git --no-pager log -7; }; f"
l8 = "! f() { git --no-pager log -8; }; f"
l9 = "! f() { git --no-pager log -9; }; f"
# Git command to show tag creation dates.
# - Optional: Add --graph to see branching lines. E.g.,
# `git tags --graph`
tags = \
log \
--date-order \
--tags \
--simplify-by-decoration \
--pretty='format:%C(green)%ad %C(red)%h %C(reset)%D' \
--date=short
tags-match = "! f() { \
git tag --format=\"%(objectname:short) %(refname:short)\" --list \"$@\"; }; f \"$@\""
# USAGE: Without params, defaults to upstream remote,
# and leads with the remote name, e.g.,:
# $ git tags-remote
# From git@github.com:thegittinsgood/easy-as-pypi.git
# 555e9969250d391e88d189ca17f60723376fcb17 refs/tags/1.0.1
# ...
# - If the upstream branch is local, prints local tags, e.g.,
# $ git tags-remote
# From .
# 555e9969250d391e88d189ca17f60723376fcb17 refs/tags/1.0.1
# USAGE: With single param, prints tags for that remote,
# and leads without the remote name (leads with nothing), e.g.,
# $ git tags-remote publish
# 555e9969250d391e88d189ca17f60723376fcb17 refs/tags/1.0.1
# - Note that multiple params always outputs nothing (and exits 0)
# unless maybe *I'm doing it wrong*. I thought maybe Git would
# output shared tags (union) from multiple remotes, but that's
# not it. So guessing it's just nothing, for real's.
tags-remote = "ls-remote --tags"
# -------
# Show just the date of the latest commit.
d1 = "! f() { git --no-pager log -1 --format=%cd --date=format:%Y-%m-%d; }; f"
# -------
# Show how many times each file has been edited, aka churn.
#
# - Show check for the whole repo:
#
# $ git churn
#
# - Show churn for specific directories:
#
# $ git churn app lib
#
# - Show churn for a time range:
#
# $ git churn --since='1 month ago'
#
# - Obvi., you can pass any git-log argument to churn.
#
# - Credits: Written by Corey Haines.
# Scriptified by Gary Bernhardt.
# Hacked by me (moved `sort -g` before `awk`, and split long line).
churn = ! \
git --no-pager log --all -M -C --name-only --format='format:' \"$@\" \
| sort \
| grep -v '^$' \
| uniq -c \
| sort -g \
| awk 'BEGIN {print "count\tfile"} {print $1 \"\t\" $2}'
# -------
# Use `git lg` to show a very concise single-line log history.
#
# - Shows one log entry per line formatted like:
#
# * HASH - DESCRIPTION (X days ago) <AUTHOR>
#
# E.g.,
#
# * acbd1234 - Docs: Update README. (4 days ago) <Your Name>
#
# - Thanks to:
#
# https://www.leaseweb.com/labs/2013/08/git-tip-beautiful-colored-and-readable-output/
lg = \
log --graph --abbrev-commit --date=relative \
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
# -------
# Use `git lg1` to see the best representation I could make of the `tig` log view.
#
# STYLE: Prefer `%C(foo)` to `%Cfoo` for readability.
# INFO.: `less -R` required here, but not if you paste this command to your terminal.
lg1 = "! f() { \
git \
--no-pager \
log \
--color=always \
--date=\"format:%a %F %H:%M %z\" \
--pretty=\"format:%h %C(blue)%cd %C(green)%<(22)%an%C(reset)%C(blue)o%C(reset)%C(red)%d%C(reset) %s\" \