-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitconfig_alias
More file actions
302 lines (287 loc) · 11.6 KB
/
gitconfig_alias
File metadata and controls
302 lines (287 loc) · 11.6 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
[alias]
# Explore your history, the commits and the code
l = "!git lds"
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short --numstat
lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
ld = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
le = log --oneline --decorate
lg = "!f() { git log -G$1; }; f"
# Show the history of a file, with diffs
filelog = log -u
fl = "!git filelog"
# Log commands to inspect (recent) history
dl = "!git ll -1"
dlc = diff --cached HEAD^
dr = "!f() { git diff "$1"^.."$1"; }; f"
lc = "!f() { git ll "$1"^.."$1"; }; f"
diffr = "!f() { git diff "$1"^.."$1"; }; f"
# Finding files and content inside files (grep)
f = "!git ls-files | grep -i"
grep = grep -Ii
gr = grep -Ii
gra = "!f() { A=$(pwd) && TOPLEVEL=$(git rev-parse --show-toplevel) && cd $TOPLEVEL && git grep --full-name -In $1 | xargs -I{} echo $TOPLEVEL/{} && cd $A; }; f"
# Going meta: List all your Aliases (la)
la = "!git config -l | grep alias | cut -c 7-"
# Rename [branch] to done-[branch]
done = "!f() { git branch | grep "$1" | cut -c 3- | grep -v done | xargs -I{} git branch -m {} done-{}; }; f"
# Assume aliases
assume = update-index --assume-unchanged
unassume = update-index --no-assume-unchanged
assumed = "!git ls-files -v | grep ^h | cut -c 3-"
unassumeall = "!git assumed | xargs git update-index --no-assume-unchanged"
assumeall = "!git st -s | awk {'print $2'} | xargs git assume"
# Tag aliases
lasttag = describe --tags --abbrev=0
lt = describe --tags --abbrev=0
# Merge aliases
ours = "!f() { git co --ours $@ && git add $@; }; f"
theirs = "!f() { git co --theirs $@ && git add $@; }; f"
# Bonus: Basic Shortcuts
a = add
ap = add -p
cp = cherry-pick
st = status -s
s = "!git st"
cl = clone
ci = commit
c = commit --verbose
ca = commit -a --verbose
cm = commit -m
cam = commit -a -m
co = checkout
cob = checkout -b
sw = switch
swc = switch -c
rs = restore
m = commit --amend --verbose
br = branch
rb = rebase -i
mt = mergetool
d = diff
diff = diff --word-diff
dc = diff --cached
ds = diff --stat
p = push
pf = push --force-with-lease
# Reset Commands
r = reset
r1 = reset HEAD^
r2 = reset HEAD^^
rh = reset --hard
rh1 = reset HEAD^ --hard
rh2 = reset HEAD^^ --hard
# Git-svn shortcuts
svnr = svn rebase
svnd = svn dcommit
svnl = svn log --oneline --show-commit
# Stash operations
sl = stash list
sa = stash apply
ss = stash save
# List branches sorted by last modified
b = "!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"
# Remove all local branches which are merged (with worktree support and confirmation)
bu = "!bash -c 'f() { \
git fetch -p; \
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD | cut -d\"/\" -f4 2>/dev/null || echo \"main\"); \
CURRENT=$(git branch --show-current); \
WORKTREE_BRANCHES=$(git worktree list --porcelain 2>/dev/null | awk \"/^branch / {print \\$2}\" | sed \"s|^refs/heads/||\" | sort -u || true); \
MERGED=$(git branch --merged | sed \"s/^[\\*+ ] //\" | grep -v \"^$DEFAULT$\" | grep -v \"^$CURRENT$\" | grep -v \"^release/\"); \
if [ -n \"$WORKTREE_BRANCHES\" ]; then \
MERGED=$(echo \"$MERGED\" | grep -vxF \"$WORKTREE_BRANCHES\" || true); \
fi; \
if [ -z \"$MERGED\" ]; then \
echo \"No merged branches to delete\"; \
return 0; \
fi; \
echo \"Merged branches to delete:\"; \
echo \"$MERGED\" | while IFS= read -r branch; do \
if [ -n \"$branch\" ]; then \
LAST_COMMIT=$(git log -1 --format=\"%cr by %an\" \"$branch\" 2>/dev/null || echo \"unknown\"); \
echo \" $branch ($LAST_COMMIT)\"; \
fi; \
done; \
echo; \
printf \"Delete these branches? [y/N] \"; \
read -r REPLY; \
if [ \"$REPLY\" = \"y\" ] || [ \"$REPLY\" = \"Y\" ]; then \
echo \"$MERGED\" | while IFS= read -r branch; do \
if [ -n \"$branch\" ]; then \
git branch -d \"$branch\"; \
fi; \
done; \
echo \"Done.\"; \
else \
echo \"Cancelled.\"; \
fi; \
}; f'"
# Dry-run version of bu (just show what would be deleted)
bud = "!bash -c 'f() { \
git fetch -p; \
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD | cut -d\"/\" -f4 2>/dev/null || echo \"main\"); \
CURRENT=$(git branch --show-current); \
WORKTREE_BRANCHES=$(git worktree list --porcelain 2>/dev/null | awk \"/^branch / {print \\$2}\" | sed \"s|^refs/heads/||\" | sort -u || true); \
MERGED=$(git branch --merged | sed \"s/^[\\*+ ] //\" | grep -v \"^$DEFAULT$\" | grep -v \"^$CURRENT$\" | grep -v \"^release/\"); \
if [ -n \"$WORKTREE_BRANCHES\" ]; then \
MERGED=$(echo \"$MERGED\" | grep -vxF \"$WORKTREE_BRANCHES\" || true); \
fi; \
if [ -z \"$MERGED\" ]; then \
echo \"No merged branches to delete\"; \
else \
echo \"Merged branches that would be deleted:\"; \
echo \"$MERGED\" | while IFS= read -r branch; do \
if [ -n \"$branch\" ]; then \
LAST_COMMIT=$(git log -1 --format=\"%cr by %an\" \"$branch\" 2>/dev/null || echo \"unknown\"); \
echo \" $branch ($LAST_COMMIT)\"; \
fi; \
done; \
fi; \
}; f'"
# Remove all local branches without upstream or with gone upstream (with worktree support and confirmation)
buf = "!bash -c 'f() { \
git fetch -p; \
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD | cut -d\"/\" -f4 2>/dev/null || echo \"main\"); \
CURRENT=$(git branch --show-current); \
WORKTREE_BRANCHES=$(git worktree list --porcelain 2>/dev/null | awk \"/^branch / {print \\$2}\" | sed \"s|^refs/heads/||\" | sort -u || true); \
GONE=$(git branch -vv | grep \": gone]\" | sed \"s/^[\\*+ ] //\" | awk \"{print \\$1}\"); \
NO_UPSTREAM=$(git branch -vv | grep -v \" \\[\" | sed \"s/^[\\*+ ] //\" | awk \"{print \\$1}\" | grep -v \"^$DEFAULT$\" | grep -v \"^$CURRENT$\" | grep -v \"^release/\"); \
TO_DELETE=$(printf \"%s\\n%s\\n\" \"$GONE\" \"$NO_UPSTREAM\" | grep -v \"^$\" | sort -u); \
if [ -n \"$WORKTREE_BRANCHES\" ]; then \
TO_DELETE=$(echo \"$TO_DELETE\" | grep -vxF \"$WORKTREE_BRANCHES\" || true); \
fi; \
if [ -z \"$TO_DELETE\" ]; then \
echo \"No branches without upstream or with gone upstream to delete\"; \
return 0; \
fi; \
echo \"Branches without upstream or with gone upstream to DELETE (force):\"; \
echo \"$TO_DELETE\" | while IFS= read -r branch; do \
if [ -n \"$branch\" ]; then \
LAST_COMMIT=$(git log -1 --format=\"%cr by %an\" \"$branch\" 2>/dev/null || echo \"unknown\"); \
if git branch -vv | grep -E \"^[\\* ] ${branch} \" | grep -q \": gone]\"; then \
UPSTREAM_STATUS=\"gone upstream\"; \
else \
UPSTREAM_STATUS=\"never pushed\"; \
fi; \
echo \" $branch ($LAST_COMMIT) [$UPSTREAM_STATUS]\"; \
fi; \
done; \
echo; \
printf \"FORCE DELETE these branches? [y/N] \"; \
read -r REPLY; \
if [ \"$REPLY\" = \"y\" ] || [ \"$REPLY\" = \"Y\" ]; then \
echo \"$TO_DELETE\" | while IFS= read -r branch; do \
if [ -n \"$branch\" ]; then \
git branch -D \"$branch\"; \
fi; \
done; \
echo \"Done.\"; \
else \
echo \"Cancelled.\"; \
fi; \
}; f'"
# Dry-run version of buf (just show what would be deleted)
bufd = "!bash -c 'f() { \
git fetch -p; \
DEFAULT=$(git symbolic-ref refs/remotes/origin/HEAD | cut -d\"/\" -f4 2>/dev/null || echo \"main\"); \
CURRENT=$(git branch --show-current); \
WORKTREE_BRANCHES=$(git worktree list --porcelain 2>/dev/null | awk \"/^branch / {print \\$2}\" | sed \"s|^refs/heads/||\" | sort -u || true); \
GONE=$(git branch -vv | grep \": gone]\" | sed \"s/^[\\*+ ] //\" | awk \"{print \\$1}\"); \
NO_UPSTREAM=$(git branch -vv | grep -v \" \\[\" | sed \"s/^[\\*+ ] //\" | awk \"{print \\$1}\" | grep -v \"^$DEFAULT$\" | grep -v \"^$CURRENT$\" | grep -v \"^release/\"); \
TO_DELETE=$(printf \"%s\\n%s\\n\" \"$GONE\" \"$NO_UPSTREAM\" | grep -v \"^$\" | sort -u); \
if [ -n \"$WORKTREE_BRANCHES\" ]; then \
TO_DELETE=$(echo \"$TO_DELETE\" | grep -vxF \"$WORKTREE_BRANCHES\" || true); \
fi; \
if [ -z \"$TO_DELETE\" ]; then \
echo \"No branches without upstream or with gone upstream to delete\"; \
else \
echo \"Branches without upstream or with gone upstream that would be FORCE DELETED:\"; \
echo \"$TO_DELETE\" | while IFS= read -r branch; do \
if [ -n \"$branch\" ]; then \
LAST_COMMIT=$(git log -1 --format=\"%cr by %an\" \"$branch\" 2>/dev/null || echo \"unknown\"); \
if git branch -vv | grep -E \"^[\\* ] ${branch} \" | grep -q \": gone]\"; then \
UPSTREAM_STATUS=\"gone upstream\"; \
else \
UPSTREAM_STATUS=\"never pushed\"; \
fi; \
echo \" $branch ($LAST_COMMIT) [$UPSTREAM_STATUS]\"; \
fi; \
done; \
fi; \
}; f'"
# Remove worktrees where the upstream branch is gone (with confirmation)
wc = "!bash -c 'f() { \
git fetch -p; \
GONE_WORKTREES=\"\"; \
while IFS= read -r line; do \
if [[ \"$line\" =~ ^worktree ]]; then \
WT_PATH=\"${line#worktree }\"; \
elif [[ \"$line\" =~ ^branch ]]; then \
WT_BRANCH=\"${line#branch refs/heads/}\"; \
if git branch -vv | grep -E \"^[+\\* ] ${WT_BRANCH} \" | grep -q \": gone]\"; then \
GONE_WORKTREES=\"$GONE_WORKTREES$WT_PATH|$WT_BRANCH\\n\"; \
fi; \
fi; \
done < <(git worktree list --porcelain 2>/dev/null); \
GONE_WORKTREES=$(printf \"$GONE_WORKTREES\" | grep -v \"^$\"); \
if [ -z \"$GONE_WORKTREES\" ]; then \
echo \"No worktrees with gone upstream branches\"; \
return 0; \
fi; \
echo \"Worktrees with gone upstream branches:\"; \
echo \"$GONE_WORKTREES\" | while IFS=\"|\" read -r wt_path wt_branch; do \
if [ -n \"$wt_path\" ]; then \
LAST_COMMIT=$(git log -1 --format=\"%cr by %an\" \"$wt_branch\" 2>/dev/null || echo \"unknown\"); \
echo \" $wt_path\"; \
echo \" branch: $wt_branch ($LAST_COMMIT)\"; \
fi; \
done; \
echo; \
printf \"Remove these worktrees and their branches? [y/N] \"; \
read -r REPLY; \
if [ \"$REPLY\" = \"y\" ] || [ \"$REPLY\" = \"Y\" ]; then \
echo \"$GONE_WORKTREES\" | while IFS=\"|\" read -r wt_path wt_branch; do \
if [ -n \"$wt_path\" ]; then \
echo \"Removing worktree: $wt_path\"; \
git worktree remove --force \"$wt_path\" 2>/dev/null || echo \" Warning: Could not remove worktree (may have uncommitted changes)\"; \
if git branch --list \"$wt_branch\" | grep -q \".\"; then \
echo \"Deleting branch: $wt_branch\"; \
git branch -D \"$wt_branch\"; \
fi; \
fi; \
done; \
echo \"Done.\"; \
else \
echo \"Cancelled.\"; \
fi; \
}; f'"
# Dry-run version of wc (just show what would be removed)
wcd = "!bash -c 'f() { \
git fetch -p; \
GONE_WORKTREES=\"\"; \
while IFS= read -r line; do \
if [[ \"$line\" =~ ^worktree ]]; then \
WT_PATH=\"${line#worktree }\"; \
elif [[ \"$line\" =~ ^branch ]]; then \
WT_BRANCH=\"${line#branch refs/heads/}\"; \
if git branch -vv | grep -E \"^[+\\* ] ${WT_BRANCH} \" | grep -q \": gone]\"; then \
GONE_WORKTREES=\"$GONE_WORKTREES$WT_PATH|$WT_BRANCH\\n\"; \
fi; \
fi; \
done < <(git worktree list --porcelain 2>/dev/null); \
GONE_WORKTREES=$(printf \"$GONE_WORKTREES\" | grep -v \"^$\"); \
if [ -z \"$GONE_WORKTREES\" ]; then \
echo \"No worktrees with gone upstream branches\"; \
else \
echo \"Worktrees with gone upstream branches that would be removed:\"; \
echo \"$GONE_WORKTREES\" | while IFS=\"|\" read -r wt_path wt_branch; do \
if [ -n \"$wt_path\" ]; then \
LAST_COMMIT=$(git log -1 --format=\"%cr by %an\" \"$wt_branch\" 2>/dev/null || echo \"unknown\"); \
echo \" $wt_path\"; \
echo \" branch: $wt_branch ($LAST_COMMIT)\"; \
fi; \
done; \
fi; \
}; f'"
# Update Repository
pl = "!git fetch -p && git pull"