Skip to content

Instantly share code, notes, and snippets.

@RichardBronosky
Last active August 17, 2023 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RichardBronosky/eb1cc18c8c23020face1fe1926d27978 to your computer and use it in GitHub Desktop.
Save RichardBronosky/eb1cc18c8c23020face1fe1926d27978 to your computer and use it in GitHub Desktop.
# to add these aliases, copy-pasta the following line (without the #):
# curl -L https://gist.githubusercontent.com/RichardBronosky/eb1cc18c8c23020face1fe1926d27978/raw/setup.sh | bash
[push]
# See: https://stackoverflow.com/a/23918418/117471
default = current
# Use SSH instead of HTTPS for github.com
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
# Use SSH instead of HTTPS for gist.github.com
[url "ssh://git@gist.github.com/"]
insteadOf = https://gist.github.com/
[alias]
alias = !git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /
aliases = alias
a = alias
st = status
br = branch
cl = clone
co = checkout
rgrep = !git grep
# Create and checkout a new branch confirming when not on master
cob = "!f(){ br=\"$(git rev-parse --abbrev-ref HEAD)\"; [[ $br == master ]] || (read -n1 -p \"Current branch is $br. Are you sure your want to create a new branch from here instead of master? [y/N] \"; echo; [[ $REPLY == [yY] ]]) && git checkout -b $@; }; f"
conflicts = "!f(){ git status --porcelain | awk '$1==\"UU\"{print $2}'; }; f"
# List most recent authors of each branch
brv = !git for-each-ref --format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p) %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=authordate refs/remotes
# Create new branch for Jira ticket
brj = "!f(){ git checkout -b \"$1-$(jira show -o summary $1 | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g;s/--*/-/g')\"; }; f"
# Add all files changes (including deletes) [to the staging area] without adding untracked (aka: new) files
up = add -uv
# Same as above, but more verbose (because it is followed by a `git status`)
update = "!git add -u; git st"
cm = commit -v
# Commit with message and don't require quotes
# Ex: git cmm Add an awesome new alias
cmm = "!f(){ git commit -m \"$*\"; }; f"
amend = commit -v --amend
# A pretty oneliner log format
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
# A pretty long log format
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
# Filter out commits by roomstogodev
qlog = log --invert-grep --author=roomstogodev
# Find files matching regex pattern (arg 1), optionally in ref/branch/commit/tag (arg 2)
f = "!f(){ filenames_pattern=\"$1\"; ref=\"${2:-HEAD}\"; git ls-tree -r --name-only \"$ref\" | grep -i \"$filenames_pattern\"; }; f"
# Rebase current branch onto origin/master
remaster = "!git fetch origin; git rebase origin/master"
re = remaster
rtgclone = "!f(){ git clone git@github.com:RoomstoGoDigital/${1}.git; }; f"
squash = "!f(){ git reset --soft HEAD~${1:-1}; git commit --amend -v --edit -m \"$(git log --format=%B --reverse HEAD~1..HEAD@{1})\"; git log -u -n$((${1:-1}+1)); ; }; f"
#template= "!f(){ ; }; f"
## TODO: create: update remote tag
## TODO: create: update local tag
## TODO: create: annotate tag
## TODO: create: delete branch
## TODO: create: rtgclone
## partial: f(){ git clone git@github.com:RoomstoGoDigital/${1}.git } f
## TODO: create: brj (branch named for a jira ticket)
## brj(){ echo "$1-$(jira show -o summary $1 | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g;s/--*/-/g')"; }
## or: f(){ glue=''; for word in "$@"; do printf -- "$glue$word"; glue='-'; done; }
## or: glue=''; for word in $(node ~/src/jira-cmd/bin/jira.js -j 1 jql 'id=RTG-3137' | jq .[0].fields.summary); do printf -- "$glue$word"; glue='-'; done;
#!/bin/bash -eux
main(){
# get the latest aliases
curl -sLo ~/.gitaliases https://gist.githubusercontent.com/RichardBronosky/eb1cc18c8c23020face1fe1926d27978/raw/.gitaliases
# include the aliases only if they don't currently get included
grep -q path=.gitaliases ~/.gitconfig 2>/dev/null || echo -e "\n[include]\n\tpath=.gitaliases" >> ~/.gitconfig
}
if [[ "$0" == "$BASH_SOURCE" || ( "$0" == "bash" && -z $BASH_SOURCE ) ]]; then main; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment