· 6 years ago · Nov 01, 2019, 05:22 PM
1[format]
2 pretty = format:%C(yellow)%h %Cblue%>(12)%ad %Cgreen%<(7)%aN%Cred%d %Creset%s
3# -*- mode: gitconfig; -*-
4# vim: set filetype=gitconfig:
5##
6# GitAlias.com file of many git alias items, including shortcuts, helpers, workflows, etc.
7#
8#
9# ## Usage
10#
11# Typical usage for a typical user:
12#
13# * Save this file as a dot file in your home directory: `~/.gitalias.txt`
14#
15# * Edit your git config dot file in your home directory such as `~/.gitconfig`
16#
17# * Include the path to this file.
18#
19# Example file `~/.gitconfig` with an entry to include the file `~/.gitalias.txt`:
20#
21# [include]
22# path = gitalias.txt
23#
24#
25# ## Usage for older git versions
26#
27# If you use an older version of git that does not have git config "include" capability,
28# or if you prefer more control, then you can simply copy/paste anything you like from
29# this file to your own git config file.
30#
31#
32# ## Customization
33#
34# If you want to use this file, and also want to change some of the items,
35# then one way is to use your git config file to include this gitalias file,
36# and also define your own alias items; a later alias takes precedence.
37#
38# Example file `~/.gitconfig` item to include the file `~/.gitalias.txt`:
39#
40# [include]
41# path = ~/.gitconfig.d/gitalias.txt
42# [alias]
43# l = log --graph --oneline
44#
45#
46# ## Links
47#
48# * [GitAlias.com website](http://gitlias.com)
49# * [GitAlias GitHub](https://github.com/gitalias)
50# * [Git Basics - Git Aliases](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases)
51# * [Git Basics - Tips and Tricks](https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks)
52#
53# ## Tracking
54#
55# * Package: gitalias
56# * Version: 21.5.0
57# * Created: 2016-06-17
58# * Updated: 2019-09-04
59# * License: GPL
60# * Contact: Joel Parker Henderson (joel@joelparkerhenderson.com)
61##
62
63[alias]
64
65 ##
66 # One letter alias for our most frequent commands.
67 #
68 # Guidelines: these aliases do not use options, because we want
69 # these aliases to be easy to compose and use in many ways.
70 ##
71
72 a = add
73 b = branch
74 c = commit
75 d = diff
76 f = fetch
77 g = grep
78 l = log
79 m = merge
80 o = checkout
81 p = pull
82 r = remote
83 s = status
84 w = whatchanged
85
86 ##
87 # Short aliases for our frequent commands.
88 #
89 # Guidelines:
90 #
91 # * Generally speaking, the alias should be in the same
92 # order as the command name followed by its options.
93 #
94 # * Right: fb = foo --bar
95 # * Wrong: bf = foo --bar
96 ##
97
98 ### add ###
99
100 # add all
101 aa = add --all
102
103 # add by patch - looks at each change, and asks if we want to put it in the repo.
104 ap = add --patch
105
106 # add just the files that are updated.
107 au = add --update
108
109 ### branch ###
110
111 # branch - edit the description
112 be = branch --edit-description
113
114 # branch and only list branches whose tips are reachable from the specified commit (HEAD if not specified).
115 bm = branch --merged
116
117 # branch and only list branches whose tips are not reachable from the specified commit (HEAD if not specified).
118 bnm = branch --no-merged
119
120 ### commit ###
121
122 # commit - amend the tip of the current branch rather than creating a new commit.
123 ca = commit --amend
124
125 # commit - amend the tip of the current branch, and edit the message.
126 cam = commit --amend --message
127
128 # commit - amend the tip of the current branch, and do not edit the message.
129 cane = commit --amend --no-edit
130
131 # commit interactive
132 ci = commit --interactive
133
134 # commit with a message
135 cm = commit --message
136
137 ### checkout ###
138
139 # checkout - update the working tree to match a branch or paths. [same as "o" for "out"]
140 co = checkout
141
142 ### cherry-pick ###
143
144 # cherry-pick - apply the changes introduced by some existing commits; useful for moving small chunks of code between branches.
145 cp = cherry-pick
146
147 # cherry-pick - abort the picking process
148 cpa = cherry-pick --abort
149
150 # cherry-pick - continue the picking process
151 cpc = cherry-pick --continue
152
153 # cherry-pick without making a commit, and when when recording the commit, append a line that says "(cherry picked from commit ...)"
154 cp-nx = cherry-pick --no-commit -x
155
156 ### diff ###
157
158 # diff - show changes not yet staged
159 dc = diff --cached
160
161 # diff - show changes about to be commited
162 ds = diff --staged
163
164 # diff - show changes but by word, not line
165 dw = diff --word-diff
166
167 # diff deep - show changes with our preferred options. Also aliased as `diff-deep`.
168 dd = diff --check --dirstat --find-copies --find-renames --histogram --color
169
170 ### clean ###
171
172 # clean everything to be pristine
173 cleanest = clean -ffdx
174
175 ### grep ###
176
177 # grep i.e. search for text
178 g = grep
179
180 # grep - show line number
181 gl = grep --line-number
182
183 # grep group - search with our preferred options. Also aliased as `grep-group`.
184 gg = grep --break --heading --line-number --color
185
186 ### log ###
187
188 # log with a text-based graphical representation of the commit history.
189 lg = log --graph
190
191 # log with one line per item.
192 lo = log --oneline
193
194 # log with patch generation.
195 lp = log --patch
196
197 # log with first parent, useful for team branch that only accepts pull requests
198 lfp = log --first-parent
199
200 # log with items appearing in topological order, i.e. descendant commits are shown before their parents.
201 lt = log --topo-order
202
203 # log like - we like this summarization our key performance indicators. Also aliased as `log-like`.
204 ll = log --graph --topo-order --date=short --abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn]%Creset %Cblue%G?%Creset'
205
206 # log like long - we like this summarization our key performance indicators. Also aliased as `log-like-long`.
207 lll = log --graph --topo-order --date=iso8601-strict --no-abbrev-commit --abbrev=40 --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn <%ce>]%Creset %Cblue%G?%Creset'
208
209 ## ls-files ##
210
211 # ls-files - show information about files in the index and the working tree; like Unix "ls" command.
212 ls = ls-files
213
214 # ls-ignored - list files that git has ignored.
215 ls-ignored = ls-files --others --i --exclude-standard
216
217 ### merge ###
218
219 # merge but without autocommit, and with a commit even if the merge resolved as a fast-forward.
220 me = merge --no-commit --no-ff
221
222 ### pull ###
223
224 # pull if a merge can be resolved as a fast-forward, otherwise fail.
225 pf = pull --ff-only
226
227 # pull with rebase - to provide a cleaner, linear, bisectable history.
228 #
229 # To automatically do "pull --rebase" everywhere:
230 #
231 # git config --global pull.rebase true
232 #
233 # To automatically do "pull --rebase" for any branch based on master:
234 #
235 # git config branch.master.rebase true
236 #
237 # To automatically do "pull --rebase" for any newly-created branches:
238 #
239 # git config --global branch.autosetuprebase always
240 #
241 # To integrate changes between branches, you can merge or rebase.
242 #
243 # When we use "git pull", git does a fetch then a merge.
244 # If we've made changes locally and someone else has pushed changes
245 # to our git host then git will automatically merge these together
246 # and create a merge commit that looks like this in the history:
247 #
248 # 12345678 - Merge branch 'foo' of bar into master
249 #
250 # When we use "git pull --rebase", git does a fetch then a rebase.
251 # A rebase resets the HEAD of your local branch to be the same as
252 # the remote HEAD, then replays your local commits back into repo.
253 # This means you don't get any noisy merge messages in your history.
254 # This gives us a linear history, and also helps with git bisect.
255 #
256 pr = pull --rebase
257
258 # pp - pull with rebase preserve of merge commits
259 #
260 # See https://stackoverflow.com/questions/21364636/git-pull-rebase-preserve-merges
261 #
262 # You should only rebase if you know (in a sort of general sense)
263 # what you are doing, and if you do know what you are doing, then you
264 # would probably prefer a merge-preserving rebase as a general rule.
265 #
266 # Although by the time you've decided that rebasing is a good idea,
267 # you will probably find that a history that has its own embedded
268 # branch-and-merge-points is not necessarily the correct "final
269 # rewritten history".
270 #
271 # That is, if it's appropriate to do a rebase at all, it's at least fairly
272 # likely that the history to be rebased is itself linear, so that the
273 # preserve-vs-flatten question is moot anyway.
274 #
275 # See https://stackoverflow.com/questions/38269092/is-it-possible-to-put-preserve-merges-in-the-gitconfig
276 #
277 # While preserving merges is probably generally superior, in at least a
278 # few ways, to discarding them when rebasing, the fact is that rebase
279 # cannot preserve them. The only thing it can do, once some commits
280 # have been copied to new commits, is re-perform them. This can have new
281 # and/or different merge conflicts, vs the last time the merge was done.
282 # You should also pay close attention to the restrictions on merge
283 # preservation in the git rebase documentation.
284 #
285 # Without getting into a lot of detail, it always seems to me that most
286 # commit graph subsets that "should be" rebased, rarely have any
287 # internal merges. If such a graph subset has a single final merge, you
288 # can simply strip away that merge (with git reset) before rebasing,
289 # and re-do that single merge manually at the end. (In fact, git rebase
290 # normally drops merge commits entirely, so you don't have to run the git
291 # reset itself in some cases. The one where you do have to run it is when
292 # the merge is into the branch onto which you intend to rebase. This is
293 # where git pull actually does the right thing when it uses
294 # `git rebase -p`, except that it fails to check for, and warn about,
295 # internal merges, which are sort of warning signs that rebasing might
296 # not be a good idea.
297 #
298 pp = pull --rebase=preserve
299
300 ### rebase ###
301
302 # rebase - forward-port local commits to the updated upstream head.
303 rb = rebase
304
305 # rebase abort - cancel the rebasing process
306 rba = rebase --abort
307
308 # rebase - continue the rebasing process after resolving a conflict manually and updating the index with the resolution.
309 rbc = rebase --continue
310
311 # rebase - restart the rebasing process by skipping the current patch.
312 rbs = rebase --skip
313
314 # rbi - rebase interactive on our unpushed commits.
315 #
316 # Before we push our local changes, we may want to do some cleanup,
317 # to improve our commit messages or squash related commits together.
318 #
319 # Let's say I've pushed two commits that are related to a new feature and
320 # I have another where I made a spelling mistake in the commit message.
321 # When I run "git rbi" I get dropped into my editor with this:
322 #
323 # pick 7f06d36 foo
324 # pick ad544d0 goo
325 # pick de3083a hoo
326 #
327 # Let's say I want to squash the "foo" and "goo" commits together,
328 # and also change "hoo" to say "whatever". To do these, I change "pick"
329 # to say "s" for squash; this tells git to squash the two together;
330 # I also edit "hoo" to rename it to "whatever". I make the file look like:
331 #
332 # pick 7f06d36 foo
333 # s ad544d0 goo
334 # r de3083a whatever
335 #
336 # This gives me two new commit messages to edit, which I update.
337 # Now when I push the remote repo host receives two commits
338 #
339 # 3400455 - foo
340 # 5dae0a0 - whatever
341 #
342 rbi = rebase --interactive @{upstream}
343
344 # See https://blog.filippo.io/git-fixup-amending-an-older-commit/
345 # This is a slightly modified version
346 fixup = "!f() { TARGET=$(git rev-parse \"$1\"); git commit --fixup=$TARGET && GIT_EDITOR=true git rebase --interactive --autosquash $TARGET~; }; f"
347
348 ### reflog ###
349
350 # reflog - reference log that manages when tips of branches are updated.
351 rl = reflog
352
353 ### remote ###
354
355 # remote - manage set of tracked repositories [same as "r"].
356 rr = remote
357
358 # remote show - gives some information about the remote <name>.
359 rrs = remote show
360
361 # remote update - fetch updates for a named set of remotes in the repository as defined by remotes.
362 rru = remote update
363
364 # remote prune - deletes all stale remote-tracking branches under <name>.
365 rrp = remote prune
366
367 incoming = !git remote update --prune; git log ..@{upstream}
368 outgoing = log @{upstream}..
369
370 # Push to all remotes
371 push-to-all-remotes = !git remote | xargs -I% -n1 git push %
372
373 ### revert ###
374
375 # revert - undo the changes from some existing commits
376 rv = revert
377
378 # revert without autocommit; useful when you're reverting more than one commits' effect to your index in a row.
379 rvnc = revert --no-commit
380
381 ### show-branch ###
382
383 # show-branch - print a list of branches and their commits.
384 sb = show-branch
385
386 ### submodule ###
387
388 # submodule - enables foreign repositories to be embedded within a dedicated subdirectory of the source tree.
389 sm = submodule
390
391 # submodule init
392 smi = submodule init
393
394 # submodule add
395 sma = submodule add
396
397 # submodule sync
398 sms = submodule sync
399
400 # submodule update
401 smu = submodule update
402
403 # submodule update with initialize
404 smui = submodule update --init
405
406 # submodule update with initialize and recursive; this is useful to bring a submodule fully up to date.
407 smuir = submodule update --init --recursive
408
409 ### status ###
410
411 # status with short format instead of full details
412 ss = status --short
413
414 # status with short format and showing branch and tracking info.
415 ssb = status --short --branch
416
417 ### ALIAS MANAGEMENT ###
418
419 # Show our defined alias list
420 aliases = "!git config --get-regexp '^alias\\.' | cut -c 7- | sed 's/ / = /'"
421
422 add-alias = "!f() { [ $# = 3 ] && git config $1 alias.\"$2\" \"$3\" && return 0 || echo \"Usage: git add-(local|global)-alias <new alias> <original command>\" >&2 && return 1; }; f"
423 add-global-alias = "!git add-alias --global"
424 add-local-alias = "!git add-alias --local"
425
426 # Rename an alias
427 rename-alias = "!f() { [ $# = 3 ] && [ $2 != $3 ] && [ ! -z \"$(git config $1 --get alias.$2)\" ] && [ -z \"$(git config $1 --get alias.$3)\" ] && git config $1 alias.$3 \"$(git config $1 --get alias.$2)\" && git config $1 --unset alias.$2 && return 0 || echo \"Usage: git rename-(local|global)-alias <alias existing name> <new alias name>\nThe alias you are going to rename must exist and new name must not exist.\" >&2 && return 1; };f"
428 rename-global-alias = "!git rename-alias --global"
429 rename-local-alias = "!git rename-alias --local"
430
431 # Last tag in the current branch
432 lasttag = describe --tags --abbrev=0
433
434 # Latest annotated tag in all branches
435 lasttagged = !git describe --tags `git rev-list --tags --max-count=1`
436
437 # From https://gist.github.com/492227
438 head = log -n1
439 heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
440 lost = !"git fsck | awk '/dangling commit/ {print $3}' | git show --format='SHA1: %C(yellow)%h%Creset %f' --stdin | awk '/SHA1/ {sub(\"SHA1: \", \"\"); print}'"
441
442 ### diff-* ###
443
444 diff-all = !"for name in $(git diff --name-only $1); do git difftool $1 $name & done"
445 diff-changes = diff --name-status -r
446 diff-stat = diff --stat --ignore-space-change -r
447 diff-staged = diff --cached
448
449 # Diff using our preferred options. A.k.a. `dd`.
450 diff-deep = diff --check --dirstat --find-copies --find-renames --histogram --color
451
452 ### grep-* ###
453
454 # Find text in any commit ever.
455 grep-all = !"f() { git rev-list --all | xargs git grep \"$@\"; }; f"
456
457 # Find text and group the output lines. A.k.a. `gg`.
458 grep-group = grep --break --heading --line-number --color
459
460 # grep with ack-like formatting
461 grep-ack = \
462 -c color.grep.linenumber=\"bold yellow\" \
463 -c color.grep.filename=\"bold green\" \
464 -c color.grep.match=\"reverse yellow\" \
465 grep --break --heading --line-number
466
467 ### init ###
468
469 # initalize a repo and immediate add an empty commit, which makes rebase easier.
470 init-empty = !"f() { git init && git commit --allow-empty --allow-empty-message --message ''; }; f"
471
472 ### merge-* ###
473
474 # Given a merge commit, find the span of commits that exist(ed).
475 # Not so useful in itself, but used by other aliases.
476 # Thanks to Rob Miller for the merge-span-* aliaes.
477 merge-span = !"f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f"
478
479 # Find the commits that were introduced by a merge
480 merge-span-log = "!git log `git merge-span .. $1`"
481
482 # Show the changes that were introduced by a merge
483 merge-span-diff = !"git diff `git merge-span ... $1`"
484
485 # Show the changes that were introduced by a merge, in your difftool
486 merge-span-difftool = !"git difftool `git merge-span ... $1`"
487
488 # Interactively rebase all the commits on the current branch
489 rebase-branch = !"git rebase --interactive `git merge-base master HEAD`"
490
491 # Sort by date for branches; can be useful for spring cleaning
492 refs-by-date = for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)'
493
494 # Find all objects that aren't referenced by any other object (orphans).
495 # To help an orphan, we create a new branch with the orphan's commit hash,
496 # then merge it into our current branch:
497 #
498 # git branch foo <commit>
499 # git merge foo
500 #
501 orphans = fsck --full
502
503 # List all blobs by size in bytes.
504 # By [CodeGnome](http://www.codegnome.com/)
505 rev-list-all-objects-sort-by-size = !"git rev-list --all --objects | awk '{print $1}'| git cat-file --batch-check | fgrep blob | sort -k3nr"
506
507
508 ### LOG ALIASES ###
509
510 # Show log of changes, most recent first
511 log-changes = log --oneline --reverse
512
513 # Show log of new commits after you fetched, with stats, excluding merges
514 log-fresh = log ORIG_HEAD.. --stat --no-merges
515
516 # Show log in our preferred format for our key performance indicators. A.k.a. `ll`.
517 log-like = log --graph --topo-order --date=short --abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn]%Creset %Cblue%G?%Creset'
518
519 # Show log in our preferred format for our key performance indicators, with long items. A.k.a. `lll`.
520 log-like-long = log --graph --topo-order --date=iso8601-strict --no-abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn <%ce>]%Creset %Cblue%G?%Creset'
521
522 # Show log with dates in our local timezone
523 log-local = log --date=local
524
525 # Show the log for my own commits by my own user email
526 log-my = !git log --author $(git config user.email)
527
528 # Show log as a graph
529 log-graph = log --graph --all --oneline --decorate
530
531 # Show the date of the earliest commit, in strict ISO 8601 format
532 log-first-date = !"git log --date-order --format=%cI | tail -1"
533
534 # Show the date of the latest commit, in strict ISO 8601 format
535 log-latest-date = log -1 --date-order --format=%cI
536
537 # Show the log of the recent hour, day, week, month, year
538 log-hour = log --since "1 hour ago"
539 log-day = log --since "1 day ago"
540 log-week = log --since "1 week ago"
541 log-month = log --since "1 month ago"
542 log-year = log --since "1 year ago"
543
544 # Show the log of my own recent hour, day, week, month, year
545 log-my-hour = log --author $(git config user.email) --since "1 hour ago"
546 log-my-day = log --author $(git config user.email) --since "1 day ago"
547 log-my-week = log --author $(git config user.email) --since "1 week ago"
548 log-my-month = log --author $(git config user.email) --since "1 month ago"
549 log-my-year = log --author $(git config user.email) --since "1 year ago"
550
551 # Show a specific format string and its number of log entries
552 log-of-format-and-count = "!f() { format=\"$1\"; shift; git log $@ --format=oneline --format="$format" | awk '{a[$0]++}END{for(i in a){print i, a[i], int((a[i]/NR)*100) \"%\"}}' | sort; }; f"
553 log-of-count-and-format = "!f() { format=\"$1\"; shift; git log $@ --format=oneline --format="$format" | awk '{a[$0]++}END{for(i in a){print a[i], int((a[i]/NR)*100) \"%\", i}}' | sort -nr; }; f"
554
555 # Show the number of log entries by a specific format string and date format string
556 log-of-format-and-count-with-date = "!f() { format=\"$1\"; shift; date_format=\"$1\"; shift; git log $@ --format=oneline --format=\"$format\" --date=format:\"$date_format\" | awk '{a[$0]++}END{for(i in a){print i, a[i], int((a[i]/NR)*100) \"%\"}}' | sort -r; }; f"
557 log-of-count-and-format-with-date = "!f() { format=\"$1\"; shift; date_format=\"$1\"; shift; git log $@ --format=oneline --format=\"$format\" --date=format:\"$date_format\" | awk '{a[$0]++}END{for(i in a){print a[i], int((a[i]/NR)*100) \"%\", i}}' | sort -nr; }; f"
558
559 # Show the number of log items by email
560 log-of-email-and-count = "!f() { git log-of-format-and-count \"%aE\" $@; }; f"
561 log-of-count-and-email = "!f() { git log-of-count-and-format \"%aE\" $@; }; f"
562
563 # Show the number of log items by hour
564 log-of-hour-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m-%dT%H\" $@ ; }; f"
565 log-of-count-and-hour = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m-%dT%H\" $@ ; }; f"
566
567 # Show the number of log items by day
568 log-of-day-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m-%d\" $@ ; }; f"
569 log-of-count-and-day = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m-%d\" $@ ; }; f"
570
571 # Show the number of log items by week
572 log-of-week-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y#%V\" $@; }; f"
573 log-of-count-and-week = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y#%V\" $@; }; f"
574
575 # Show the number of log items by month
576 log-of-month-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m\" $@ ; }; f"
577 log-of-count-and-month = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m\" $@ ; }; f"
578
579 # Show the number of log items by year
580 log-of-year-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y\" $@ ; }; f"
581 log-of-count-and-year = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y\" $@ ; }; f"
582
583 # Show the number of log items by hour of day
584 log-of-hour-of-day-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%H\" $@; }; f"
585 log-of-count-and-hour-of-day = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%H\" $@; }; f"
586
587 # Show the number of log items by day of week
588 log-of-day-of-week-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%u\" $@; }; f"
589 log-of-count-and-day-of-week = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%u\" $@; }; f"
590
591 # Show the number of log items by week of year
592 log-of-week-of-year-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%V\" $@; }; f"
593 log-of-count-and-week-of-year = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%V\" $@; }; f"
594
595 # TODO
596 log-refs = log --all --graph --decorate --oneline --simplify-by-decoration --no-merges
597 log-timeline = log --format='%h %an %ar - %s'
598 log-local = log --oneline origin..HEAD
599 log-fetched = log --oneline HEAD..origin/master
600
601 # chart: show a summary chart of activity per author.
602 #
603 # Example:
604 #
605 # $ git chart
606 # ..X..........X...2..12 alice@example.com
607 # ....2..2..13.......... bob@example.com
608 # 2.....1....11......... carol@example.com
609 # ..1............1..1... david@example.com
610 # ....1.......1.3.3.22.2 eve@example.com
611 #
612 # The chart rows are the authors.
613 # TODO: sort the rows meaningfully,
614 # such as alphabetically, or by count.
615 #
616 # The chart columns are the days.
617 # The chart column prints one character per day.
618 #
619 # * For 1-9 commits, show the number.
620 # * For 10 or more commits, show "X" as a visual indicator.
621 # * For no commits, show "." as a visual placeholder.
622 #
623 # The chart timeline adjusts the date range automatically:
624 #
625 # * The timeline starts with the date of the earliest commit.
626 # * The timeline stops with the date of the latest commit.
627 # * The intent is to show the most relevant information.
628 #
629 chart = "!f() { \
630 git log --format=oneline --format=\"%aE %at\" --since=\"48 days ago\" $@ | \
631 awk ' \
632 function time_to_slot(t) { return strftime(\"%Y-%m-%d\", t, true) } \
633 function count_to_char(i) { return (i > 0) ? ((i < 10) ? i : \"X\") : \".\" } \
634 BEGIN { \
635 time_min = systime(); time_max = 0; \
636 SECONDS_PER_DAY=86400; \
637 } \
638 { \
639 item = $1; \
640 time = 0 + $2; \
641 if (time > time_max){ time_max = time } else if (time < time_min){ time_min = time }; \
642 slot = time_to_slot(time); \
643 items[item]++; \
644 slots[slot]++; \
645 views[item, slot]++; \
646 } \
647 END{ \
648 printf(\"Chart time range %s to %s.\\n\", time_to_slot(time_min), time_to_slot(time_max)); \
649 time_max_add = time_max += SECONDS_PER_DAY; \
650 for(item in items){ \
651 row = \"\"; \
652 for(time = time_min; time < time_max_add; time += SECONDS_PER_DAY) { \
653 slot = time_to_slot(time); \
654 count = views[item, slot]; \
655 row = row count_to_char(count); \
656 } \
657 print row, item; \
658 } \
659 }'; \
660 }; f"
661
662 # churn: show log of files that have many changes
663 #
664 # * Written by (Corey Haines)[http://coreyhaines.com/]
665 # * Scriptified by Gary Bernhardt
666 # * Obtained from https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn
667 # * Edited for GitAlias.com repo by Joel Parker Henderson
668 # * Comments by Mislav http://mislav.uniqpath.com/2014/02/hidden-documentation/
669 #
670 # Show churn for whole repo:
671 #
672 # $ git churn
673 #
674 # Show churn for specific directories:
675 #
676 # $ git churn app lib
677 #
678 # Show churn for a time range:
679 #
680 # $ git churn --since='1 month ago'
681 #
682 # These are all standard arguments to `git log`.
683 #
684 # It's possible to get valuable insight from history of a project not only
685 # by viewing individual commits, but by analyzing sets of changes as a whole.
686 # For instance, `git churn` compiles stats about which files change the most.
687 #
688 # For example, to see where work on an app was focused on in the past month:
689 #
690 # $ git churn --since='1 month ago' app/ | tail
691 #
692 # This can also highlight potential problems with technical debt in a project.
693 # A specific file changing too often is generally a red flag, since it probably
694 # means the file either needed to be frequently fixed for bugs, or the file
695 # holds too much responsibility and should be split into smaller units.
696 #
697 # Similar methods of history analysis can be employed to see which people were
698 # responsible recently for development of a certain part of the codebase.
699 #
700 # For instance, to see who contributed most to the API part of an application:
701 #
702 # $ git log --format='%an' --since='1 month ago' app/controllers/api/ | \
703 # sort | uniq -c | sort -rn | head
704 #
705 # 109 Alice Anderson
706 # 13 Bob Brown
707 # 7 Carol Clark
708 #
709 churn = !"f() { git log --all --find-copies --find-renames --name-only --format='format:' \"$@\" | awk 'NF{a[$0]++}END{for(i in a){print a[i], i}}' | sort -rn;};f"
710
711
712 # summary: print a helpful summary of some typical metrics
713 summary = "!f() { \
714 printf \"Summary of this branch...\n\"; \
715 printf \"%s\n\" $(git rev-parse --abbrev-ref HEAD); \
716 printf \"%s first commit timestamp\n\" $(git log --date-order --format=%cI | tail -1); \
717 printf \"%s latest commit timestamp\n\" $(git log -1 --date-order --format=%cI); \
718 printf \"%d commit count\n\" $(git rev-list --count HEAD); \
719 printf \"%d date count\n\" $(git log --format=oneline --format=\"%ad\" --date=format:\"%Y-%m-%d\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
720 printf \"%d tag count\n\" $(git tag | wc -l); \
721 printf \"%d author count\n\" $(git log --format=oneline --format=\"%aE\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
722 printf \"%d committer count\n\" $(git log --format=oneline --format=\"%cE\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
723 printf \"%d local branch count\n\" $(git branch | grep -v \" -> \" | wc -l); \
724 printf \"%d remote branch count\n\" $(git branch -r | grep -v \" -> \" | wc -l); \
725 printf \"\nSummary of this directory...\n\"; \
726 printf \"%s\n\" $(pwd); \
727 printf \"%d file count via git ls-files\n\" $(git ls-files | wc -l); \
728 printf \"%d file count via find command\n\" $(find . | wc -l); \
729 printf \"%d disk usage\n\" $(du -s | awk '{print $1}'); \
730 printf \"\nMost-active authors, with commit count and %%...\n\"; git log-of-count-and-email | head -7; \
731 printf \"\nMost-active dates, with commit count and %%...\n\"; git log-of-count-and-day | head -7; \
732 printf \"\nMost-active files, with churn count\n\"; git churn | head -7; \
733 }; f"
734
735 ### LOOKUP ALIASES ###
736
737 # whois: given a string for an author, try to figure out full name and email:
738 whois = "!sh -c 'git log --regexp-ignore-case -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -"
739
740 # Given any git object, try to show it briefly
741 whatis = show --no-patch --pretty='tformat:%h (%s, %ad)' --date=short
742
743 # Show who contributed with summarized changes
744 who = shortlog --summary --
745
746 # Show who contributed, in descending order by number of commits
747 whorank = shortlog --summary --numbered --no-merges
748
749 # List all issues mentioned in commit messages between range of commits
750 #
751 # Replace `\\\"ISSUE-[0-9]\\+\\\"` regular expression with one matching your issue tracking system.
752 # For Jira it should be as simple as putting your project name in place of `ISSUE`.
753 #
754 # Best used with tags:
755 # $ git issues v1.0..v1.1
756 #
757 # But will work with any valid commit range:
758 # $ git issues master..HEAD
759
760 issues = !sh -c \"git log $1 --oneline | grep -o \\\"ISSUE-[0-9]\\+\\\" | sort -u\"
761
762 # Show the commit's parents
763 commit-parents = !"f(){ git cat-file -p \"${*:-HEAD}\" | sed -n '/0/,/^ *$/{/^parent /p}'; };f"
764
765 # Is the commit a merge commit? If yes exit 0, else exit 1
766 commit-is-merge = !"f(){ [ -n \"$(git commit-parents \"$*\" | sed '0,/^parent /d')\" ];};f"
767
768 # Show the commit's keyword-marked lines.
769 #
770 # Show each line in the commit message that starts with zero or more blanks,
771 # then a keyword (alphanum and dash characters), then a colon.
772 #
773 # Example commit:
774 #
775 # commit ce505d161fccdbc8d4bf12047846de7433ad6d04
776 # Author: Joel Parker Henderson <joel@joelparkerhenderson.com>
777 # Date: Tue May 28 11:53:47 2019 -0700
778 #
779 # Add feature foo
780 #
781 # This commit is to add feature foo.
782 #
783 # Time: 5 hours
784 # Cost: 600 USD
785 #
786 # Command:
787 #
788 # $ git commit-message-key-lines ce505d161fccdbc8d4bf12047846de7433ad6d04
789 # Commit: ce505d161fccdbc8d4bf12047846de7433ad6d04
790 # Author: Joel Parker Henderson <joel@joelparkerhenderson.com>
791 # Date: Tue May 28 11:53:47 2019 -0700
792 # Time: 5 hours
793 # Cost: 600 USD
794 #
795 # Normalize the output:
796 #
797 # * Start the output with "Commit: <commit>"
798 #
799 # * Omit leading blanks
800 #
801 # * After the colon, use one space (not tab, not multiple spaces, etc.)
802 #
803 # Known issues:
804 #
805 # * TODO: improve the keyword matcher so it requires the keyword to end
806 # in an alphanum (not a dash), and also so the dash is a separator i.e.
807 # the matcher does not accept a dash followed by another dash.
808 #
809 commit-message-key-lines = "!f(){ echo \"Commit: $1\"; git log \"$1\" --format=fuller | grep \"^[[:blank:]]*[[:alnum:]][-[:alnum:]]*:\" | sed \"s/^[[:blank:]]*//; s/:[[:blank:]]*/: /\"; }; f"
810
811
812 ### WORKFLOW ALIASES ###
813
814 # Clone a git repository including all submodules
815 cloner = clone --recursive
816
817 # Stash aliases for push & pop
818 #
819 # Note that if you are using an older version of git, before 2.16.0,
820 # then you can use the older "stash save" instead of the newer "stash push".
821 save = stash push
822 pop = stash pop
823
824 # Stash snapshot - from http://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
825 # Take a snapshot of your current working tree without removing changes.
826 # This is handy for refactoring where you can't quite fit what you've done
827 # into a commit but daren't stray too far from now without a backup.
828 #
829 # Running this:
830 #
831 # $ git snapshot
832 #
833 # Creates this stash:
834 #
835 # stash@{0}: On feature/handy-git-tricks: snapshot: Mon Apr 8 12:39:06 BST 2013
836 #
837 # And seemingly no changes to your working tree.
838 #
839 snapshot = !git stash push "snapshot: $(date)" && git stash apply "stash@{0}"
840
841 # When you're a little worried that the world is coming to an end
842 panic = !tar cvf ../panic.tar *
843
844 # Create an archive file of everything in the repo
845 archive = !"f() { top=$(rev-parse --show-toplevel); cd $top; tar cvf $top.tar $top ; }; f"
846
847 # Do everything we can to synchronize all changes for the current branch.
848 #
849 # * git get: fetch and prune, pull and rebase, then update submodules
850 # * git put: commit all items, then push
851 #
852 # TODO: handle tags, delete superfluous branches, and add error handing.
853 #
854 get = !git fetch --prune && git pull --rebase=preserve && git submodule update --init --recursive
855 put = !git commit --all && git push
856
857 # Do everything we can to make the local repo like the master branch.
858 #
859 # TODO: handle tags, and delete superfluous branches, and add error handling.
860 #
861 mastery = !git checkout master && git fetch origin --prune && git reset --hard origin/master
862
863 # Ignore all untracked files by appending them to .gitignore:
864 ignore = "!git status | grep -P \"^\\t\" | grep -vF .gitignore | sed \"s/^\\t//\" >> .gitignore"
865
866 # Do a push/pull for just one branch
867 push1 = "!git push origin $(git branch-name)"
868 pull1 = "!git pull origin $(git branch-name)"
869
870 # Track and untrack, with default parameters, and with printing the command
871 track = "!f(){ branch=$(git rev-parse --abbrev-ref HEAD); cmd=\"git branch $branch -u ${1:-origin}/${2:-$branch}\"; echo $cmd; $cmd; }; f"
872 untrack = "!f(){ branch=$(git rev-parse --abbrev-ref HEAD); cmd=\"git branch --unset-upstream ${1:-$branch}\"; echo $cmd; $cmd; }; f"
873
874 # Track all remote branches that aren't already being tracked;
875 # this is a bit hacky because of the parsing, and we welcome
876 # better code that works using more-specific git commands.
877 track-all-remote-branches = !"f() { git branch -r | grep -v ' -> ' | sed 's/^ \\+origin\\///' ; }; f"
878
879 ##
880 # Reset & Undo
881 ##
882
883 # Reset and undo aliases are ways to move backwards on the commit chain.
884 # We find that novices prefer the wording "undo"; experts prefer "reset".
885 reset-commit = reset --soft HEAD~1
886 reset-commit-hard = reset --hard HEAD~1
887 reset-commit-clean = !git reset --hard HEAD~1 && git clean -fd
888 reset-to-pristine = !git reset --hard && git clean -ffdx
889 reset-to-upstream = !git reset --hard $(git upstream-name)
890
891 # Undo is simply a synonym for "reset" because "undo" can help novices.
892 undo-commit = reset --soft HEAD~1
893 undo-commit-hard = reset --hard HEAD~1
894 undo-commit-clean = !git reset --hard HEAD~1 && git clean -fd
895 undo-to-pristine = !git reset --hard && git clean -ffdx
896 undo-to-upstream = !git reset --hard $(git upstream-name)
897
898 # Nicknames
899 uncommit = reset --soft HEAD~1
900 unadd = reset HEAD
901 unstage = reset HEAD
902
903 # Discard changes in a (list of) file(s) in working tree
904 discard = checkout --
905
906 # Clean and discard changes and untracked files in working tree
907 cleanout = !git clean -df && git checkout -- .
908
909 # Expunge a file everywhere; this command is typically for a serious problem,
910 # such as accidentally committing a file of sensitive data, such as passwords.
911 # After you use command, you will likely need to force push everything.
912 # See https://help.github.com/articles/removing-sensitive-data-from-a-repository/
913 expunge = !"f() { git filter-branch --force --index-filter \"git rm --cached --ignore-unmatch $1\" --prune-empty --tag-name-filter cat -- --all }; f"
914
915 # Edit all files of the given type
916 edit-cached = !"f() { git ls-files --cached | sort -u ; }; `git var GIT_EDITOR` `f`"
917 edit-deleted = !"f() { git ls-files --deleted | sort -u ; }; `git var GIT_EDITOR` `f`"
918 edit-others = !"f() { git ls-files --others | sort -u ; }; `git var GIT_EDITOR` `f`"
919 edit-ignored = !"f() { git ls-files --ignored | sort -u ; }; `git var GIT_EDITOR` `f`"
920 edit-killed = !"f() { git ls-files --killed | sort -u ; }; `git var GIT_EDITOR` `f`"
921 edit-modified = !"f() { git ls-files --modified | sort -u ; }; `git var GIT_EDITOR` `f`"
922 edit-stage = !"f() { git ls-files --stage | cut -f2 | sort -u ; }; `git var GIT_EDITOR` `f`"
923
924 # Editing and adding conflicted files: when we get many merge conflicts
925 # and want to quickly solve them using an editor, then add the files.
926 edit-unmerged = !"f() { git ls-files --unmerged | cut -f2 | sort -u ; }; `git var GIT_EDITOR` `f`"
927 add-unmerged = !"f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"
928
929 # Ours & Theirs - easy merging when you know which files you want
930 #
931 # Sometimes during a merge you want to take a file from one side wholesale.
932 #
933 # The following aliases expose the ours and theirs commands which let you
934 # pick a file(s) from the current branch or the merged branch respectively.
935 #
936 # * ours: checkout our version of a file and add it
937 # * theirs: checkout their version of a file and add it
938 #
939 # N.b. the function is there as hack to get $@ doing
940 # what you would expect it to as a shell user.
941 #
942 ours = !"f() { git checkout --ours $@ && git add $@; }; f"
943 theirs = !"f() { git checkout --theirs $@ && git add $@; }; f"
944
945 # Work In Progress: from https://gist.github.com/492227 and VonC on stackoverflow.
946 # This enables a quick way to add all new and modified files to the index,
947 # while cleaning the index from the files removed from the working tree;
948 # this cleaning will facilitate a rebase, because there won't be any conflict
949 # due to an "unclean" working directory (not in sync with the index).
950 # The unwip will restore the deleted files to the working tree.
951 wip = !"git add --all; git ls-files --deleted -z | xargs -0 git rm; git commit --message=wip"
952 unwip = !"git log -n 1 | grep -q -c wip && git reset HEAD~1"
953
954 # Assume
955 #
956 # Sometimes we want to change a file in a repo, but never check in your edits.
957 # We can't use .gitignore because the file is tracked. We use update-index.
958 #
959 # If you interact with big corporate projects, such as projects in Subversion,
960 # then you might run into the need to ignore certain files which are under
961 # Subversion control, yet you need to modify them but not commit.
962 # The assume-unchanged flag comes to the rescue.
963 #
964 # Suppose we want to edit passwords.txt and for god's sake never check it in:
965 #
966 # $ git status
967 # modified passwords.txt
968 # modified foo.txt
969 #
970 # $ git assume passwords.txt
971 # $ git status
972 # modified foo.txt
973 #
974 # $ git assumed
975 # passwords.txt
976 #
977 # $ git unassume passwords.txt
978 # $ git status
979 # modified passwords.txt
980 # modified foo.txt
981 #
982 # Thanks to http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
983 # Thanks to http://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
984
985 assume = update-index --assume-unchanged
986 unassume = update-index --no-assume-unchanged
987 assume-all = "!git st -s | awk {'print $2'} | xargs git assume"
988 unassume-all = "!git assumed | xargs git update-index --no-assume-unchanged"
989 assumed = !"git ls-files -v | grep ^h | cut -c 3-"
990
991 # Delete all branches that have already been merged into the master branch.
992 master-cleanse = !git master-cleanse-local; git master-cleanse-remote
993
994 # Delete all local branches that have been merged into the local master branch.
995 master-cleanse-local = "!git checkout master && git branch --merged | xargs git branch --delete"
996
997 # Delete all remote branches that have been merged into the remote master branch.
998 master-cleanse-remote = !"git branch --remotes --merged origin/master | sed 's# *origin/##' | grep -v '^master$' xargs -I% git push origin :% 2>&1 | grep --colour=never 'deleted'"
999
1000 # Publish the current branch by pushing it to the remote "origin",
1001 # and setting the current branch to track the upstream branch.
1002 publish = !"git push --set-upstream origin $(git branch-name)"
1003
1004 # Unpublish the current branch by deleting the
1005 # remote version of the current branch.
1006 unpublish = !"git push origin :$(git branch-name)"
1007
1008 # Delete a branch name, then create the same branch name based on master -
1009 # useful if you have, for example, a development branch and master branch
1010 # and they go out of sync, and you want to nuke the development branch.
1011 #
1012 # Calls the `publish` and `unpublish` aliases.
1013 #
1014 reincarnate = !"f() { [[ -n $@ ]] && git checkout \"$@\" && git unpublish && git checkout master && git branch -D \"$@\" && git checkout -b \"$@\" && git publish; }; f"
1015
1016 # Friendly wording is easier to remember.
1017 # Thanks to http://gggritso.com/human-git-aliases
1018 branches = branch -a
1019 tags = tag -n1 --list
1020 stashes = stash list
1021
1022
1023 ### SHELL SCRIPTING ALIASES ###
1024
1025 # Get the top level directory name
1026 top-name = rev-parse --show-toplevel
1027
1028 # Get the current branch name
1029 branch-name = rev-parse --abbrev-ref HEAD
1030
1031 # Get the upstream branch name
1032 upstream-name = !git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)
1033
1034 # Execute shell scripts. Git always runs scripts in the top directory.
1035 # For example "git exec pwd" will always show you the top directory.
1036 exec = ! exec
1037
1038
1039 ### MAINTENANCE ALIASES ###
1040
1041 # pruner: prune everything that is unreachable now.
1042 #
1043 # This command takes a long time to run, perhaps even overnight.
1044 #
1045 # This is useful for removing unreachable objects from all places.
1046 #
1047 # By [CodeGnome](http://www.codegnome.com/)
1048 #
1049 pruner = !"git prune --expire=now; git reflog expire --expire-unreachable=now --rewrite --all"
1050
1051 # repacker: repack a repo the way Linus recommends.
1052 #
1053 # This command takes a long time to run, perhaps even overnight.
1054 #
1055 # It does the equivalent of "git gc --aggressive"
1056 # but done *properly*, which is to do something like:
1057 #
1058 # git repack -a -d --depth=250 --window=250
1059 #
1060 # The depth setting is about how deep the delta chains can be;
1061 # make them longer for old history - it's worth the space overhead.
1062 #
1063 # The window setting is about how big an object window we want
1064 # each delta candidate to scan.
1065 #
1066 # And here, you might well want to add the "-f" flag (which is
1067 # the "drop all old deltas", since you now are actually trying
1068 # to make sure that this one actually finds good candidates.
1069 #
1070 # And then it's going to take forever and a day (ie a "do it overnight"
1071 # thing). But the end result is that everybody downstream from that
1072 # repository will get much better packs, without having to spend any effort
1073 # on it themselves.
1074 #
1075 # http://metalinguist.wordpress.com/2007/12/06/the-woes-of-git-gc-aggressive-and-how-git-deltas-work/
1076 #
1077 # We also add the --window-memory limit of 1 gig, which helps protect
1078 # us from a window that has very large objects such as binary blobs.
1079 #
1080 repacker = repack -a -d -f --depth=300 --window=300 --window-memory=1g
1081
1082 # Do everything we can to optimize the repository.
1083 #
1084 # This command takes a long time to run, perhaps even overnight.
1085 #
1086 # Currently, this command simply calls `git pruner` and `git repacker`.
1087 # There's a step that may be unnecessarying, calling `git prune-pack`.
1088 #
1089 optimize = !git pruner; git repacker; git prune-packed
1090
1091
1092 ### ADVANCED ALIASES ###
1093
1094 # Search for a given string in all patches and print commit messages.
1095 # Posted by Mikko Rantalainen on StackOverflow.
1096 #
1097 # Example: search for any commit that adds or removes string "foobar"
1098 # git searchcommits foobar
1099 #
1100 # Example: search commits for string "foobar" in directory src/lib
1101 # git searchcommits foobar src/lib
1102 #
1103 # Example: search commits for "foobar", print full diff of commit with 1 line context
1104 # git searchcommits foobar --pickaxe-all -U1 src/lib
1105 searchcommits = !"f() { query=\"$1\"; shift; git log -S\"$query\" \"$@\"; }; f \"$@\""
1106
1107 # A 'debug' alias to help debugging builtins: when debugging builtins,
1108 # we use gdb to analyze the runtime state. However, we have to disable
1109 # the pager, and often we have to call the program with arguments.
1110 # If the program to debug is a builtin, we use this alias.
1111 debug = !GIT_PAGER= gdb --args git
1112
1113 # Getting the diff of only one function: when we want to see just the
1114 # differences of one function in one file in two different commits,
1115 # we create two temp files which contain only the function, then diff.
1116 # Use this alias this way: git funcdiff <old-rev> <new-rev> <path> <function>
1117 # diff-func = !sh -c "git show \"\$1:\$3\" | sed -n \"/^[^ \t].*\$4(/,/^}/p\" > .tmp1 && git show \"\$2:\$3\" | sed -n \"/^[^ \t].*\$4(/,/^}/p\" > .tmp2 && git diff --no-index .tmp1 .tmp2" -
1118
1119 # Calling "interdiff" between commits: if upstream applied a
1120 # slightly modified patch, and we want to see the modifications,
1121 # we use the program interdiff of the patchutils package.
1122 intercommit = !sh -c 'git show "$1" > .git/commit1 && git show "$2" > .git/commit2 && interdiff .git/commit[12] | less -FRS' -
1123
1124 # Prune all your stale remote branches: there's no way to tell
1125 # git remote update to prune stale branches, and git remote prune
1126 # does not understand --all. So here is a shell command to do it.
1127 prune-all = !git remote | xargs -n 1 git remote prune
1128
1129 # Thanks to cody cutrer
1130 cherry-pick-merge = !"sh -c 'git cherry-pick --no-commit --mainline 1 $0 && \
1131 git log -1 --pretty=%P $0 | cut -b 42- > .git/MERGE_HEAD && \
1132 git commit --verbose'"
1133
1134 # Thanks to jtolds on stackoverflow
1135 remote-ref = !"sh -c ' \
1136 local_ref=$(git symbolic-ref HEAD); \
1137 local_name=${local_ref##refs/heads/}; \
1138 remote=$(git config branch.\"#local_name\".remote || echo origin); \
1139 remote_ref=$(git config branch.\"$local_name\".merge); \
1140 remote_name=${remote_ref##refs/heads/}; \
1141 echo remotes/$remote/$remote_name'"
1142
1143 # Thanks to jtolds on stackoverflow
1144 rebase-recent = !git rebase --interactive $(git remote-ref)
1145
1146 # Use graphviz for display.
1147 # This produces output that can be displayed using dotty, for example:
1148 # $ git graphviz HEAD~100..HEAD~60 | dotty /dev/stdin
1149 # $ git graphviz --first-parent master | dotty /dev/stdin
1150 graphviz = !"f() { echo 'digraph git {' ; git log --pretty='format: %h -> { %p }' \"$@\" | sed 's/[0-9a-f][0-9a-f]*/\"&\"/g' ; echo '}'; }; f"
1151
1152 # Serve the local directory by starting a git server daemon, so others can pull/push from my machine
1153 serve = "-c daemon.receivepack=true daemon --base-path=. --export-all --reuseaddr --verbose"
1154
1155 ##########################################################################
1156
1157 ##
1158 # Git alias settings suitable for topic branches.
1159 #
1160 # These aliases are simple starting points for a simple topic flow.
1161 # Lots of people have lots of ideas about how to do various git flows.
1162 #
1163 # Some people like to use a topic branch for a new feature, or a
1164 # hotfix patch, or refactoring work, or some spike research, etc.
1165 #
1166 # Our simple workflow:
1167 #
1168 # $ git topic-start foo
1169 # ... do work ...
1170 # $ git topic-stop
1171 #
1172 # If you want more control, then you can use these building blocks:
1173 #
1174 # $ git topic-create foo
1175 # $ git topic-delete
1176 #
1177 # If you want to pull and push while you're working, then use these:
1178 #
1179 # $ git topic-pull
1180 # $ git topic-push
1181 #
1182 # If you want to manage your branch while you're working, then use these:
1183 #
1184 # $ git topic-sync
1185 # $ git topic-rename
1186 #
1187 # Ideas for your own alias customizations:
1188 #
1189 # * Notify your team, such as by sending an email, posting to chat, etc.
1190 # * Trigger testing of the new topic branch to ensure all tests succeed.
1191 # * Update the project management software.
1192 #
1193 # Customize these aliases as you like for your own workflow.
1194 ##
1195
1196 ##
1197 # Provide the name of the topic base branch, such as "master".
1198 #
1199 # When we create a new topic branch, we base it on the topic base branch.
1200 # Many projects use the default "master" branch; some projects use custom
1201 # branches, such as "trunk", "develop", "integrate", "release", etc.
1202 #
1203 # Customize this alias as you like for your own workflow.
1204 ##
1205
1206 topic-base-branch-name = "!f(){ \
1207 printf \"master\n\"; \
1208 };f"
1209
1210 ### START & STOP ###
1211
1212 ##
1213 # Start a topic branch.
1214 #
1215 # Example:
1216 #
1217 # git topic-start foo
1218 #
1219 # We use this alias to begin work on a new feature,
1220 # new task, new fix, new refactor, new optimization, etc.
1221 #
1222 # This implementation does these steps:
1223 #
1224 # 1. Create the topic branch.
1225 # 2. Push the topic branch.
1226 #
1227 # Customize this alias as you like for your own workflow.
1228 ##
1229
1230 topic-start = "!f(){ \
1231 topic_branch=\"$1\"; \
1232 git topic-create \"$topic_branch\"; \
1233 git topic-push; \
1234 };f"
1235
1236 ##
1237 # Stop a topic branch; this must be the current branch.
1238 #
1239 # Example:
1240 #
1241 # git topic-stop
1242 #
1243 # We use this alias to complete work on a new feature,
1244 # new task, new fix, new refactor, new optimization, etc.
1245 #
1246 # This implementation does these:
1247 #
1248 # 1. Push the topic branch.
1249 # 2. Delete the topic branch.
1250 #
1251 # Customize this alias as you like for your own workflow.
1252 ##
1253
1254 topic-stop = "!f(){ \
1255 git topic-push; \
1256 git topic-delete; \
1257 };f"
1258
1259 ### CREATE & DELETE ###
1260
1261 ##
1262 # Create a topic branch.
1263 #
1264 # Example:
1265 #
1266 # git topic-create foo
1267 #
1268 # This implementation does these steps:
1269 #
1270 # 1. Update the base branch locally.
1271 # 2. Create a new branch with your topic name, based on the base branch.
1272 #
1273 # Customize this alias as you like for your own workflow.
1274 ##
1275
1276 topic-create = "!f(){ \
1277 topic_branch=\"$1\"; \
1278 base_branch=$(git topic-base-branch-name); \
1279 git checkout \"$base_branch\"; git pull; \
1280 git checkout -b \"$topic_branch\" \"$base_branch\"; \
1281 };f"
1282
1283 ##
1284 # Delete a topic branch; this must be the current branch.
1285 #
1286 # Example:
1287 #
1288 # git topic-delete
1289 #
1290 # This implementation does these:
1291 #
1292 # 1. Delete the topic branch locally.
1293 # 2. Delete the topic branch remotely.
1294 #
1295 # Customize this for your own workflow preferences.
1296 #
1297 # If you use a sharing site such a GitHub, and use typical settings,
1298 # then this implementation deletes your branch for the site.
1299 #
1300 # Many teams choose to delete topic branches when they are finished,
1301 # to keep the repositories clean and with a smaller number of branches.
1302 #
1303 # If git says "unable to push to unqualified destination" then it means
1304 # that the remote branch doesn't exist, so git is unable to delete it.
1305 # That's fine; it means someone else has already deleted the branch.
1306 # To synchronize your branch list, use "git fetch --prune".
1307 #
1308 # Customize this alias as you like for your own workflow.
1309 ##
1310
1311 topic-delete = "!f(){ \
1312 topic_branch=$(git branch-name); \
1313 base_branch=$(git topic-base-branch-name); \
1314 if [ \"$topic_branch\" = \"$base_branch\" ]; then \
1315 printf \"You are trying to delete your git topic branch,\n\"; \
1316 printf \"but you are on the base branch: $topic_base_branch.\n\"; \
1317 printf \"Please checkout the topic branch that you want,\n\"; \
1318 printf \"then retry the git topic delete command.\n\"; \
1319 else \
1320 git checkout \"$base_branch\"; \
1321 git branch --delete \"$topic_branch\"; \
1322 git push origin \":$topic_branch\"; \
1323 fi; \
1324 };f"
1325
1326
1327 ### PULL & PUSH ###
1328
1329 ##
1330 # Update the current topic branch by pulling changes.
1331 #
1332 # Example:
1333 #
1334 # git topic-pull
1335 #
1336 # This implementation does these:
1337 #
1338 # 1. Pull the topic branch from the origin.
1339 #
1340 # If you use any kind of testing framework, or test driven development,
1341 # then it can be wise to test your topic immediately after running this,
1342 # to ensure that any available updates are successfully integrated.
1343 #
1344 # Customize this alias as you like for your own workflow.
1345 #
1346 # * E.g. some teams prefer to use `pull --rebase`.
1347 ##
1348
1349 topic-pull = "!f(){ \
1350 git pull; \
1351 };f"
1352
1353 ##
1354 # Update the current topic branch by pushing changes.
1355 #
1356 # Example:
1357 #
1358 # git topic-push
1359 #
1360 # This implementation does these:
1361 #
1362 # 1. Push the topic branch to the origin.
1363 # 2. Set the upstream tracking.
1364 #
1365 # Customize this for your own workflow preferences.
1366 #
1367 # If you use a sharing site such a GitHub, and use typical settings,
1368 # then this implementation makes your branch visible to collaborators.
1369 #
1370 # Many teams share branches before they are fully ready, to help
1371 # the team provide feedback on the work-in-progress.
1372 #
1373 # Customize this alias as you like for your own workflow.
1374 ##
1375
1376 topic-push = "!f(){ \
1377 topic_branch=$(git branch-name); \
1378 git push --set-upstream origin \"$topic_branch\"; \
1379 };f"
1380
1381 ### MANAGE TOPIC BRANCHES ###
1382
1383 ##
1384 # Update the current topic branch with up-to-date base branch
1385 # by either rebasing or merging.
1386 #
1387 # Example:
1388 #
1389 # git topic-rebase-base
1390 #
1391 # This implementation does these:
1392 #
1393 # 1. Run checkout base_branch.
1394 # 2. Pull base_branch
1395 # 3. Run checkout topic_branch.
1396 # 4. Merge/Rebase base_branch.
1397 #
1398 # Customize this alias as you like for your own workflow.
1399 ##
1400
1401 topic-rebase-base = "!f(){ \
1402 topic_branch=$(git branch-name); \
1403 base_branch=$(git topic-base-branch-name); \
1404 git checkout \"$base_branch\"; git pull; \
1405 git checkout \"$topic_branch\"; git rebase \"$base_branch\"; \
1406 };f"
1407
1408 topic-merge-base = "!f(){ \
1409 topic_branch=$(git branch-name); \
1410 base_branch=$(git topic-base-branch-name); \
1411 git checkout \"$base_branch\"; git pull; \
1412 git checkout \"$topic_branch\"; git merge \"$base_branch\"; \
1413 };f"
1414
1415 ##
1416 # Update the current topic branch by synchronizing changes.
1417 #
1418 # Example:
1419 #
1420 # git topic-sync
1421 #
1422 # This implementation does these:
1423 #
1424 # 1. Run topic-pull.
1425 # 2. Run topic-push.
1426 #
1427 # Customize this alias as you like for your own workflow.
1428 ##
1429
1430 topic-sync = "!f(){ \
1431 git topic-pull; \
1432 git topic-push; \
1433 };f"
1434
1435 ##
1436 # Move/rename the current topic branch.
1437 #
1438 # Example:
1439 #
1440 # git topic-move hello
1441 #
1442 # This implementation does these:
1443 #
1444 # 1. Move/rename the local branch.
1445 # 2. Move/rename the remote branch by pushing to origin.
1446 #
1447 # Customize this alias as you like for your own workflow.
1448 ##
1449
1450 topic-move = "!f(){ \
1451 new_branch=\"$1\"; \
1452 old_branch=$(git branch-name); \
1453 git branch --move \"$old_branch\" \"$new_branch\"; \
1454 git push origin \":$old_branch\" \"$new_branch\"; \
1455 };f"
1456
1457
1458 ##########################################################################
1459
1460 ##
1461 # Git aliases suitable for particular software integrations and tooling,
1462 # such as other version control system e.g. CVS, Subversion, etc.
1463 ##
1464
1465 ### CVS ALIAS ###
1466
1467 cvs-i = cvsimport -k -a
1468 cvs-e = cvsexportcommit -u -p
1469
1470 ### GitK ###
1471
1472 # show conflicting merge in gitk:
1473 gitk-conflict = !gitk --left-right HEAD...MERGE_HEAD
1474
1475 # show full history in gitk (including "deleted" branches and stashes)
1476 gitk-history-all = !gitk --all $( git fsck | awk '/dangling commit/ {print $3}' )
1477
1478 ### Ruby on Rails ###
1479
1480 # Do everything we can to synchronize all changes for a Ruby On Rails app.
1481 # We like using rebase (instead of merge), bundle for gems, and rake db:migrate
1482 rails-get = !"git pull --rebase; git submodule update --init --recursive; bundle check || bundle install; bundle exec rake db:migrate; bundle exec rake db:test:prepare"
1483
1484 ### Subversion ###
1485
1486 svn-b = svn branch
1487 svn-m = merge --squash
1488 svn-c = svn dcommit
1489 svn-cp = !GIT_EDITOR='sed -i /^git-svn-id:/d' git cherry-pick --edit
1490
1491 ##########################################################################
1492
1493 ##
1494 # Git aliases to correct common typing mistakes, which git built-in autocorrection
1495 # does not handle
1496 ##
1497
1498 ### Use with shell alias `gitp = git` ###
1499
1500 ull = pull
1501 ush = push
1502[core]
1503 excludesfile = /Users/hong/.gitignore
1504[user]
1505 name = UGLHong
1506 email = lohtonghong@gmail.com