Skip to content

Commit cbe646a

Browse files
committed
♻️ Clean up git aliases
1 parent e9a4c64 commit cbe646a

File tree

4 files changed

+68
-21
lines changed

4 files changed

+68
-21
lines changed

.bash_profile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,28 @@ alias git-summary='~/git/git-summary/git-summary'
7272
alias s='subl'
7373
alias sm='smerge'
7474
alias xdg-open='open'
75-
alias envls='pyenv virtualenvs'
76-
alias i="ipython -i -c '
75+
alias pyenvls='pyenv virtualenvs | grep --invert-match "/envs/"'
76+
alias i="
77+
python -c 'import autotime, ipdb' || pip install ipython-autotime ipdb
78+
79+
ipython -i -c '
7780
# just make sure to use escaped double quotes
78-
import os, numpy as np, pandas as pd
81+
import os, logging, numpy as np, pandas as pd
7982
from pathlib import Path
8083
here = Path(\".\").resolve()
8184
85+
# set to WARNING by default
86+
logging.basicConfig(level=logging.INFO)
87+
logger = logging.getLogger(__name__)
88+
8289
# hotreload imports on each prompt
8390
%load_ext autoreload
8491
%autoreload 2
8592
8693
# pip install ipython-autotime
8794
%load_ext autotime
8895
'"
96+
export PYTHONBREAKPOINT=ipdb.set_trace
8997

9098

9199

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2019, David de Lange
3+
Copyright (c) 2019, ddelange
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ https://github.com/naokazuterada/MarkdownTOC#usage -->
2727
- [Git with 2FA](#git-with-2fa)
2828
- [Mac OSX specifics](#mac-osx-specifics)
2929
- [Aliases](#aliases)
30+
- [Shorthands](#shorthands)
31+
- [Cleaning](#cleaning)
32+
- [Rewriting history](#rewriting-history)
3033
- [Split diff](#split-diff)
3134
- [Mergetool](#mergetool)
3235
- [Cleanup \(different options\)](#cleanup-different-options)
@@ -359,34 +362,69 @@ git config --global push.followTags true # https://git-scm.com/docs/git-config#D
359362

360363
##### Aliases
361364

365+
Some of these aliases depend on one another, in which case it's noted in the comments.
366+
367+
###### Shorthands
362368
```bash
363-
git config --global alias.st "status"
364-
git config --global alias.cm "commit"
365-
git config --global alias.ca "commit -am"
366-
git config --global alias.cap '! f() { git commit -am "$@" && git push --set-upstream origin "$(git rev-parse --abbrev-ref HEAD)"; }; f'
367-
git config --global alias.camend "commit --amend -am"
368-
git config --global alias.amend "commit --amend --no-edit -a"
369369
git config --global alias.br "branch"
370+
git config --global alias.ca "commit -am"
371+
git config --global alias.cm "commit"
370372
git config --global alias.co "checkout"
371373
git config --global alias.mt "mergetool"
372-
git config --global alias.lg "log --graph --decorate --pretty=oneline --abbrev-commit"
373-
git config --global alias.fp "fetch -p --all" # purge and fetch all remotes
374-
git config --global alias.defaultbranch '! f() { echo $(git remote show origin | grep "HEAD branch" | cut -d ":" -f 2 | xargs); }; f' # https://stackoverflow.com/questions/28666357#comment101797372_50056710
375-
git config --global alias.df '! f() { git icdiff --color=always "$@" | less -eR; }; f' # no FX (keep output in terminal)
376-
git config --global alias.pr '! git push --set-upstream origin "$(git rev-parse --abbrev-ref HEAD)"' # push a new branch. will be overwritten if git-extras is installed
377-
git config --global alias.dm '! git fetch -p && for branch in `git branch -vv | grep '"': gone] ' | awk '"'{print $1}'"'"'`; do git branch -D $branch; done' # 'delete merged' - local branches that have been deleted on remote
378-
git config --global alias.gg '! f() { git checkout "${1:-$(git defaultbranch)}" && git dm && git pull; }; f' # git gg develop -- no arg: defaultbranch. Return to default branch (or specified branch), delete merged, pull branch
379-
git config --global alias.pall '! f() { START=$(git branch | grep "\*" | sed "s/^.//"); for i in $(git branch | sed "s/^.//"); do git checkout $i; git pull || break; done; git checkout $START; }; f' # 'pull all' - pull local branches that have been updated on remote
380-
git config --global alias.undo '! f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f' # https://megakemp.com/2016/08/25/git-undo/
381-
git config --global alias.squashlast '"!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f"' # Squash the last x commits; will prompt you with auto-squashed commit messages
374+
git config --global alias.st "status"
375+
# split diff - needs icdiff (see below) - use `git icdiff` to keep output in terminal after less quits
376+
git config --global alias.df '! f() { diff=$(git icdiff --color=always "$@") && test "$diff" && echo "$diff" | less -eR; }; f'
377+
# who needs the default verbose git log? - also try `git lg --all`
378+
git config --global alias.lg "log --graph --oneline"
379+
# tested with GitHub remote - ref https://stackoverflow.com/questions/28666357#comment101797372_50056710
380+
git config --global alias.defaultbranch '! f() { echo $(git remote show origin | grep "HEAD branch" | cut -d ":" -f 2 | xargs); }; f'
381+
# summary of all configured aliases
382382
git config --global alias.alias "! git config --get-regexp '^alias\.' | sed -e s/^alias\.// | grep -v ^'alias ' | sed 's/ /#/' | column -ts#"
383+
# "commit all & push" - needs ca,pr - usage `git cap 'Fix bug'` - runs autoformatting pre-commit hooks, commits all modified tracked files with message, and push
384+
git config --global alias.cap '! f() { git ca "$@" && git pr; }; f'
385+
# "pull request" - push new or existing branch skipping the usual --set-upstream error - alias will be overwritten when git-extras is installed
386+
git config --global alias.pr '! git push --set-upstream origin "$(git rev-parse --abbrev-ref HEAD)"'
387+
```
388+
389+
###### Cleaning
390+
```bash
391+
# "delete merged" - delete all local branches (-D) that have been deleted (merged) on remote
392+
git config --global alias.dm '! git fetch -p && for branch in `git branch -vv | grep '"': gone] ' | awk '"'{print $1}'"'"'`; do git branch -D $branch; done'
393+
# "fetch purge" - before fetching, remove any remote-tracking references that no longer exist on the remote
394+
git config --global alias.fp "fetch -p --all"
395+
# "rinse & repeat" - needs defaultbranch,dm - usage `git gg [develop]` - return to default branch (or specified branch), delete merged and pull
396+
git config --global alias.gg '! f() { git checkout "${1:-$(git defaultbranch)}" && git dm && git pull; }; f'
397+
# "pull all" - pull all local branches and return to original branch
398+
git config --global alias.pall '! f() { \
399+
START=$(git branch | grep "\*" | sed "s/^.//"); \
400+
for i in $(git branch | sed "s/^.//"); do \
401+
git checkout $i; \
402+
git pull || break; \
403+
done; \
404+
git checkout $START; \
405+
}; f'
406+
```
407+
408+
###### Rewriting history
409+
```bash
410+
# "commit all amend" last commit, adding all modified tracked files to the it without editing the commit message
411+
git config --global alias.amend "commit --amend --no-edit -a"
412+
# "commit all amend with message" - add all modified tracked files to the last commit with a new commit message
413+
git config --global alias.camend "commit --amend -am"
414+
# "squash last" X commits - allowing to edit a pre-generated commit message before committing - known caveat: when trying to squash into an initial commit, the reset fails
415+
git config --global alias.squashlast '"!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f"'
416+
# "undo" whatever you did last, for instance an erroneous squashlast - ref https://megakemp.com/2016/08/25/git-undo/
417+
git config --global alias.undo '! f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'
383418
```
384419

385420

386421
##### Split diff
387422

423+
- `git df` (above) uses less that keeps a clean terminal
424+
- `git icdiff` (below) uses new core.pager that leaves less output in terminal after exiting
425+
388426
```bash
389-
pip install git+https://github.com/jeffkaufman/icdiff.git # usage: 'git df' using 'less' or 'git icdiff' without 'less'
427+
pip install git+https://github.com/jeffkaufman/icdiff.git
390428
git config --global --replace-all core.pager 'less -+$LESS -eFRSX' # with double quotes, $ will be evaluated
391429
git config --global icdiff.options "--highlight --line-numbers --numlines=3"
392430
git config --global difftool.icdiff.cmd 'icdiff --highlight --line-numbers --numlines=3 $LOCAL $REMOTE'

htoprc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ left_meters=AllCPUs2 CPU Memory Swap
3434
left_meter_modes=1 1 1 1
3535
right_meters=DateTime Tasks LoadAverage Uptime
3636
right_meter_modes=2 2 2 2
37+
hide_function_bar=0

0 commit comments

Comments
 (0)