-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitconfig
201 lines (184 loc) · 7.14 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
# correct typos
[help]
autocorrect = 1
[core]
excludesfile = ~/.gitignore
logAllRefUpdates = true
; https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more
attributesfile = ~/.gitattributes
; let the $EDITOR variable decide that
; editor = vim
[alias]
a = add
aa = add -A
b = branch
remove-local = "!git branch | grep -vE \"(master|main)\" | xargs git branch -D"
del = branch -D
; either 2 arguments: `from` and `to`, or just `to` if you're on the branch already
rename = "!f() { if [ $# -eq 2 ]; then local from=$1; else local from=`git symbolic-ref -q --short HEAD`; fi; local to=${2:-$1}; git branch -m $from $to; git push --no-verify origin :$from $to; git push --no-verify origin -u $to; }; f"
c = commit
amend = commit --amend
abort = "!git rebase --abort 2>/dev/null || git merge --abort 2>/dev/null || git cherry-pick --abort 2>/dev/null"
cl = "!f() { if echo \"$*\" | grep -E \"(https?:|git@|git:|\\.git[[:space:]]|\\.git$)\" > /dev/null; then git clone \"$@\"; else gh repo clone -- \"$@\"; fi }; f"
co = checkout
contains = describe --all --contains
d = diff
d = diff
ds = diff --staged
dt = difftool
dts = difftool --staged
f = fetch
graph = log --graph --pretty=oneline --abbrev-commit --decorate --all
l = log
track = update-index --no-assume-unchanged
untrack = update-index --assume-unchanged
w = worktree
wt = worktree
wa = worktree add
wr = worktree remove
wl = worktree list
wm = worktree move
# requires FZF
autofixup = "!f() { COMMIT=$(git log --pretty=oneline | fzf | awk '{print $1}'); git commit --fixup $COMMIT; GIT_SEQUENCE_EDITOR=: git rebase --autostash --autosquash -i $COMMIT^; }; f"
# fshow - git commit browser
# https://gist.github.com/junegunn/f4fca918e937e6bf5bad#gistcomment-1666125
fshow = "!f() { \
git log --graph --color=always \
--format=\"%C(auto)%h%d %s %C(black)%C(bold)%cr\" \"$@\" | \
fzf --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \
--bind \"ctrl-m:execute: \
echo {} | grep -o '[a-f0-9]\\{7\\}' | head -1 | \
xargs -I % sh -c 'git show --color=always % | less -R' \"; \
}; f"
last = log -1 HEAD
file-commits = "!f() { git log --pretty=\"%H\" --follow \"$1\"; }; f"
file-commits-since = "!f() { git log --pretty=\"%H\" --follow ${2:-master}.. \"$1\"; }; f"
m = merge
mt = mergetool
# https://stackoverflow.com/a/50056710
default = "!f() { REMOTE=$(git remote); BRANCH=$(LC_ALL=C git remote show $REMOTE | grep \"HEAD branch\" | sed 's/.*: //'); git checkout $BRANCH; }; f"
master = checkout master
main = checkout main
p = push
pu = pull
r = reset
rh = reset --hard
rs = reset --soft
hard = reset --hard
soft = reset --soft
unstage = reset HEAD
re = rebase
s = status
sa = submodule add
si = submodule init
su = submodule update
ss = submodule status
st = stash
save = stash save
pop = stash pop
sub = submodule
# https://stackoverflow.com/a/36593218/676756
submodule-remove = "!f() { \
git submodule deinit -f \"$1\"; \
git rm -rf \"$1\"; \
rm -rf \".git/modules/${1}\"; }; f"
t = tag
set-url = remote set-url origin
modified = ls-files --modified --others --exclude-standard
; changed files in a commit
; https://stackoverflow.com/a/424142
changed-files = show --pretty="" --name-only
staged = diff --name-only --cached
# custom functions
changelog = "!git log --oneline --no-merges $1..HEAD"
difference = "!git log --oneline $1..$2"
# refresh the date of commits (https://dev.to/konstantin/refresh-commit-date-2cnh)
refresh-date = "!f() { git rebase HEAD~$1 --ignore-date; }; f"
local = "!git log --oneline --no-merges origin/$(git rev-parse --abbrev-ref HEAD).."
mindiff = diff -w --word-diff-regex=. --color-words -U0
overview = log --all --since='2 weeks' --oneline --no-merges
recent = "!git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format=\"%(refname:short)\" | fzf --no-sort --bind='ctrl-m:execute(git checkout {})+abort'"
sneak = commit -a --amend --no-edit
stats = shortlog -sn
; --no-merges to hide merge commits
today = "!git log --since='00:00:00' --all --decorate --oneline --author=$(git config user.email)"
yesterday = "!git log --since='1 day ago 00:00:00' --before='1 day ago 23:59:59' --all --decorate --oneline --author=$(git config user.email)"
last-friday="!git log --since='last friday 00:00:00' --before='last friday 23:59:59' --all --decorate --oneline --author=$(git config user.email)"
wdiff = diff --word-diff
upstream = "!git fetch && git log --oneline --no-merges ..origin/$(git rev-parse --abbrev-ref HEAD)"
zip-modified = "!zip modified.zip $(git modified && git staged)"
; open = "!gh repo view --web"
o = !git open
code = open
view = open
user = "!gh api user | sed -E 's/.*\"login\":\"?([^,\"]*)\"?.*/\\1/'"
repos = "!repos() { local user=\"${1?}\";shift 1; gh api --paginate graphql -f user=\"$user\" \"$@\" \
-f query='query($user: String!, $per_page: Int = 100, $after: String) { user(login: $user) { \
repositories(first: $per_page, after: $after) { nodes { nameWithOwner }, pageInfo { hasNextPage, endCursor } } } }';}; \
repos \"$(git user)\" | sed -E 's/}/\\\n/g' | grep \"nameWithOwner\" | sed -E 's/.*\"nameWithOwner\":\"?([^,\"]*)\"?.*/\\1/g'"
repo = "!gh api repos/:owner/:repo | sed -E 's/.*\"full_name\":\"?([^,\"]*)\"?.*/\\1/'"
rename-repo = "!f() { gh api -XPATCH repos/:owner/:repo -f name=$1 | grep -e \"ssh_url\" | sed -E 's/.*\"ssh_url\":\"?([^,\"]*)\"?.*/\\1/' | xargs git set-url; }; f"
# git comment 7 "some comment"
comment = "!f() { gh api --silent \"repos/:owner/:repo/issues/$1/comments\" --raw-field \"body=$2\"; }; f"
; Open PR on GitHub if it exists and create it if it doesn't exist
; https://stackoverflow.com/a/26759734/676756
pr = "!if [ -x \"$(command -v gh)\" ]; then \
if ! gh pr view --web &> /dev/null; then \
gh pr create --web; \
fi \
else \
echo \"gh is not installed\"; \
fi"
pr-view = pr
pr-open = pr
; https://elijahmanor.com/blog/gh-pr-fzf-preview
pr-list = "!GH_FORCE_TTY=100% gh pr list | fzf --ansi --preview 'GH_FORCE_TTY=100% gh pr view {1}' --preview-window down --header-lines 3 | awk '{print $1}' | xargs gh pr checkout"
; alias = ! git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /
[push]
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushautoSetupRemote
autoSetupRemote = true
# push easily. http://stackoverflow.com/a/23918418/89484
default = current
# use separate file for username / github token / etc
[include]
# user name and email only
path = ~/.gitconfig.user.local
# other local configuration
path = ~/.gitconfig.local
[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = true
pager = true
[color "diff"]
meta = 11
commit = yellow bold
frag = magenta bold
old = red bold
new = green bold
whitespace = red reverse
[color "diff-highlight"]
oldNormal = red bold
oldHighlight = red bold 52
newNormal = green bold
newHighlight = green bold 22
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "status"]
added = yellow
changed = green
untracked = cyan
[mergetool]
prompt = false
[difftool]
prompt = false
[credential]
UseHttpPath = true
[init]
defaultBranch = main
[commit]
verbose = true