-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitconfig
372 lines (348 loc) · 14.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
[user]
name = toejough
email = [email protected]
[init]
defaultBranch = main
[core]
ignoresFile = /Users/joe/.gitignore
excludesFile = /Users/joe/.gitignore
ignorecase = false
autocrlf = input
pager = delta
[interactive]
diffFilter = delta --color-only
[delta]
features = line-numbers decorations side-by-side
[delta "decorations"]
commit-decoration-style = bold yellow box ul
file-style = yellow box
file-decoration-style = blue box
hunk-header-decoration-style = yellow ul
[credential]
helper = osxkeychain
[merge]
tool = vimdiff
conflictstyle = diff3
[alias]
# [ data ]
name = rev-parse --abbrev-ref HEAD
last-common-commit = merge-base HEAD
has-local-changes-from = "!f() { if ( git fetch && git diff --quiet $(git last-common-commit $1) ); then test; fi }; f"
has-changes-from-branch = "!git has-local-changes-from origin/$(git name)"
has-changes-from-main = "!git has-local-changes-from origin/main"
branches = branch -a
tags = tag
stashes = stash list
graph = log --graph --branches --remotes --tags --topo-order --oneline --decorate
raw-upstream = "!git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)"
upstream = "![[ -n $(git raw-upstream) ]] || ( echo 'no upstream branch set.' && test ) && git raw-upstream"
# [ branch actions ]
rename = "!f() { \
printf '[*] identifying branch...'; \
local NAME=\"$(git name)\"; \
echo 'branch is:' \"$NAME\"; \
echo '[*] renaming local branch to:' \"$1\"; \
git branch -m \"$1\" && \
echo '[*] pushing newly renamed branch to remote' && \
git push origin --set-upstream \"$1\" && \
echo '[*] removing old remote branch' && \
git push origin :\"$NAME\"; \
}; f"
prune-dead-branches = "!f() { \
set -x; \
git checkout main && \
git fetch && \
git pull && \
git stop-working-on-gone && \
git remote prune origin && \
git worktree prune && \
git branch --merged | egrep -v '^\\s*main$|^\\s*\\*.*|^\\+' | xargs -L1 git branch -d && \
git branch -vv | ack ': gone' | awk '{print $1}' | xargs -L1 git branch -D; \
git remove-stale-tags; \
}; f"
cleanup-from = "!f() { if git has-local-changes-from $1; then git rebase -i $(git last-common-commit $1); else echo 'Same as last common commit with '$1; fi }; f"
# [ re-tagging actions ]
re-tag-from = "!f() { \
local LOCAL_TAG=\"local-base.$(git name)\"; \
local BRANCH_TAG=\"branch-base.$(git name)\"; \
local CURRENT_BRANCH=\"$(git name)\"; \
local BRANCHED_FROM=\"${1}\"; \
local BRANCH_START=\"$(git last-common-commit ${BRANCHED_FROM})\"; \
local LOCAL_START=\"$(git last-common-commit origin/${CURRENT_BRANCH})\"; \
git tag -f \"${LOCAL_TAG}\" \"${LOCAL_START}\"; \
git tag -f \"${BRANCH_TAG}\" \"${BRANCH_START}\"; \
git push -f origin \"${BRANCH_TAG}\"; \
}; f"
# [ file state actions ]
# unstage a staged file
unstage = reset HEAD --
# discard a file's changes
discard = checkout --
# undo last commit
uncommit = reset --soft HEAD~
# remove all local state
nuke-local-state = "!git reset --hard origin/$(git name) && git clean -xdff"
# [ workflow actions ]
# Get a true representation of the remote main, locally
update-main = "!git checkout main && git fetch && git reset --hard origin/main"
# Create a new branch from where-ever you are now.
# Also tags this as your branch's base point for easier rebasing later.
# This tag will get pushed to your remote branch for branch history tracking.
# Also tags this as your local commit history start for easier rebasing later.
# This tag will *not* get pushed to your remote branch - it's for local history tracking _only_.
new-branch = "!f() { \
git checkout -b $1; \
git tag \"branch-base.$1\"; \
git push --set-upstream origin $(git name); \
git push -f origin \"branch-base.$1\"; \
git tag \"local-base.$1\"; \
}; f"
fire = "!git new-branch $USER/FIRE/$(date | tr ' :' '-') && git add -A && git commit -m FIRE && git push-branch"
# clean your local commits up before pushing to the remote
clean-local = "!f() { \
local START=\"local-base.$(git name)\"; \
local STOP=\"$(git name)\"; \
local ONTO=\"${START}\"; \
git rebase -i --onto \"${ONTO}\" \"${START}\" \"${STOP}\"; \
}; f"
# rebase your branch from the local base point onto the given commit/branch/tag
# This may or may not be the origin version of this branch (git fetch; git rebase-local-onto origin/<branch>)
rebase-local-onto = "!f() { \
local START=\"local-base.$(git name)\"; \
local STOP=\"$(git name)\"; \
local ONTO=\"${1}\"; \
git rebase -i --onto \"${ONTO}\" \"${START}\" \"${STOP}\" || return 1; \
git tag -f \"${START}\" \"${ONTO}\"; \
}; f"
# clean your branch's commits up before merging to another branch
clean-branch = "!f() { \
local START=\"branch-base.$(git name)\"; \
local STOP=\"$(git name)\"; \
local ONTO=\"${START}\"; \
git rebase -i --onto \"${ONTO}\" \"${START}\" \"${STOP}\" || return 1; \
local LOCAL=\"local-base.$(git name)\"; \
git tag -f \"${LOCAL}\" \"${ONTO}\"; \
}; f"
# rebase your branch from the branch base point onto the given commit/branch/tag
rebase-branch-onto = "!f() { \
local START=\"branch-base.$(git name)\"; \
local STOP=\"$(git name)\"; \
local ONTO=\"${1}\"; \
git rebase -i --onto \"${ONTO}\" \"${START}\" \"${STOP}\" || return 1; \
local LOCAL=\"local-base.$(git name)\"; \
git tag -f \"${LOCAL}\" \"${ONTO}\" && \
git tag -f \"${START}\" \"${ONTO}\"; \
}; f"
# push your branch to the remote
force-push-branch = "!f() { \
local BRANCH=\"$(git name)\"; \
local ONTO=\"${1}\"; \
git push --force-with-lease || return 1; \
local LOCAL=\"local-base.${BRANCH}\"; \
local BRANCH_TAG=\"branch-base.${BRANCH}\"; \
git push --force-with-lease origin $BRANCH_TAG; \
git tag -f \"${LOCAL}\" \"${BRANCH}\"; \
}; f"
push-branch = "!f() { \
local BRANCH=\"$(git name)\"; \
local ONTO=\"${1}\"; \
git push || return 1; \
local LOCAL=\"local-base.${BRANCH}\"; \
local BRANCH_TAG=\"branch-base.${BRANCH}\"; \
git push -f origin $BRANCH_TAG; \
git tag -f \"${LOCAL}\" \"${BRANCH}\"; \
}; f"
remove-tags-for = "!f() { \
local LOCAL=\"local-base.${1}\"; \
local BRANCH=\"branch-base.${1}\"; \
git tag --delete \"${LOCAL}\"; \
git tag --delete \"${BRANCH}\"; \
git push --delete origin \"${LOCAL}\"; \
git push --delete origin \"${BRANCH}\"; \
}; f"
remove-stale-tags = "!git tags | cut -f 2 -d. | sort | uniq | xargs -L1 -I% fish -c \"git branch --all | ack % > /dev/null; or git remove-tags-for %\""
# [ Force-push recovery ]
recover-last-remote = "!git checkout -b recover.$(git name) && git reset --hard refs/remotes/origin/$(git name)@{1}; echo 'triple check this is the branch state you want, and then switch back to your branch, run git use-recovery-version and git integrate-main again."
use-recovery-version = "!git reset --hard recover.$(git name); echo 'if you are really sure, git integrate-main.'"
# [ Worktree ]
workon-new = "!f() { \
local parent_location=$(git parent) && \
local name=$(echo $1 | tr . -); \
local location=$parent_location/../$(basename $parent_location)-worktrees/$name; \
echo \"adding worktree for branch $1 at $location\"; \
git worktree add -b $1 --checkout $location $(git name); \
echo \"adding rebase tags\"; \
git tag \"branch-base.$1\"; \
git tag \"local-base.$1\"; \
echo \"moving to worktree directory\"; \
cd $location && \
echo \"setting origin to $1\"; \
git push --set-upstream origin $1; \
echo \"pushing branch rebase tag\"; \
git push --force-with-lease origin \"branch-base.$1\"; \
fish -C \"cd $location; set -u GIT_DIR\"; \
}; f"
workon-existing = "!f() { \
local parent_location=$(git parent) && \
local name=$(echo $1 | tr . -); \
local location=$parent_location/../$(basename $parent_location)-worktrees/$name; \
echo \"adding worktree for branch $1 at $location\"; \
git worktree add --checkout $location $1; \
echo \"moving to worktree directory\"; \
cd $location && \
fish -C \"cd $location; set -u GIT_DIR\"; \
}; f"
workon = "!f() { \
local choice=$(git branches | fzf --print-query | tail -1); \
if test -z \"$choice\"; then \
return; \
fi; \
echo \"chose: $choice\"; \
local choice=$(echo \"$choice\" | sed 's/remotes\\/origin\\///'); \
echo \"remote-stripped: $choice\"; \
local choice=$(echo \"$choice\" | sed 's/[*+[:space:]]*//g'); \
echo \"char-stripped: $choice\"; \
local is_branch=$(git branches | ag $choice'$' > /dev/null && echo yes || echo no); \
echo \"is branch?: $is_branch\"; \
if test $is_branch = no; then \
echo \"workon-new\"; \
git workon-new $choice; \
return; \
fi; \
local current_location=$(git worktree list | ag '\\['$choice']$' | awk '{print $1}'); \
echo \"current location: $current_location\"; \
if test -z \"$current_location\"; then \
echo \"workon-existing\"; \
git workon-existing $choice; \
return; \
fi; \
echo \"goto-existing\"; \
fish -C \"cd $current_location; set -u GIT_DIR\"; \
}; f"
stop-working-on = "!f() { \
local parent_location=$(git parent) && \
cd $parent_location && \
local location=$(git worktree list | ag -v \"$parent_location\\s+\" | fzf | awk '{print $1'}) && \
if test -z \"$location\"; then \
echo \"no directory $location\" \
return; \
fi; \
echo $location | xargs -L1 -p rm -rf && \
rmdir -p $(dirname $location) &> /dev/null; \
git worktree prune && \
echo \"removed worktree at $location\";\
fish -c \"set -U last_dir $parent_location\"; \
fish -C \"set -u GIT_DIR\"; \
}; f"
stop-working-on-gone = "!f() { \
local parent_location=$(git parent) && \
cd $parent_location && \
git worktree prune && \
git branch -vv | ack '^\\+' | ack ': gone' | awk '{print $4}' | sed -E 's/\\((.*)\\)/\\1/g' | xargs -L1 -I% echo \"removing worktree at %\" && \
git branch -vv | ack '^\\+' | ack ': gone' | awk '{print $4}' | sed -E 's/\\((.*)\\)/\\1/g' | xargs -L1 -I% rm -rf % && \
git branch -vv | ack '^\\+' | ack ': gone' | awk '{print $4}' | sed -E 's/\\((.*)\\)/\\1/g' | xargs -L1 -I% fish -c \"rmdir -p (dirname %)\" &> /dev/null && \
git worktree prune && \
fish -c \"set -U last_dir $parent_location\"; \
}; f"
# rev-parse --git-dir gets the git directory this branch is getting its git info from (not necessarily
# the root directory, if we're in a worktree. eg /User/foo/repo/.git/worktrees/branch
# awk -F/ separates the result by /. eg " " User foo repo .git worktrees branch
# for i=2 starts at the second arg. eg User
# NF-3 stops before the third arg. eg .git
# awk auto-sets empty vars, so d=d... effectively joins the fields with the / separator prepended to each
parent = "!f() { \
local maybe_parent=$(git rev-parse --git-dir | awk -F/ '{ {for(i=2; i<=NF-3;i++) {d=d \"/\" $i}} {print d }}') && \
if test -n \"$maybe_parent\"; then \
echo $maybe_parent; \
else \
git root; \
fi; \
}; f"
root = "!git rev-parse --show-toplevel"
# [ TDD-ish ]
# commit a proof-of-concept
poc = "!f() { \
git commit -m \"[POC] $1\"; \
}; f"
# commit failing test code
red = "!f() { \
git commit -m \"[RED] $1\"; \
}; f"
# commit WIP towards green tests
wip = "!f() { \
git commit -m \"[WIP] $1\"; \
}; f"
# commit feature implementation code resulting in a passing test
green = "!f() { \
git commit -m \"[GREEN] $1\"; \
}; f"
# commit code reorganization updates
refactor = "!f() { \
git commit -m \"[REFACTOR] $1\"; \
}; f"
# commit non-tdd things
other = "!f() { \
git commit -m \"[OTHER] $1\"; \
}; f"
# commit a fixup
fixup = "!f() { \
git commit --fixup $(git log --oneline branch-base.$(git name)..HEAD | fzf | cut -d' ' -f 1); \
}; f"
# commit a squash
squash = "!f() { \
git commit -m \"$1\" --squash $(git log --oneline branch-base.$(git name)..HEAD | fzf | cut -d' ' -f 1); \
}; f"
# delete local and remote from inside branch
nevermind = "!f() { \
git push -d origin $(git name); \
git branch -d $(git name); \
}; f"
# delete local and remote
delete-branch = "!f() { \
local choice=$(git branches | fzf --print-query | tail -1 | awk '{print substr($0,2)}'); \
if test -z \"$choice\"; then \
return; \
fi; \
git push -d origin $choice; \
git branch -d $choice; \
}; f"
[push]
default = simple
followTags = false
[commit]
template = /Users/joe/dotfiles/git-commit-template.txt
[help]
autocorrect = 20
[pull]
ff = only
rebase = merges
[remote.origin]
tagOpt = --tags
[rebase]
autosquash = true
[fetch]
prune = true
[diff]
compactionHeuristic = true
mnemonicPrefix = true
renames = copies
indentHeuristic = true
algorithm = patience
colorMoved = dimmed-zebra
colorMovedWS = allow-indentation-change
;[pager]
;log = "diff-so-fancy | less --tabs=4 -RFX"
;show = "diff-so-fancy | less --tabs=4 -RFX"
;diff = "diff-so-fancy | less --tabs=4 -RFX"
[rerere]
enabled = true
[url "[email protected]:"]
insteadOf = https://gitlab.com
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
; make go use ssh so I can use private repos in github for personal projects
[url "ssh://[email protected]/"]
insteadOf = https://github.com/