Skip to content

Instantly share code, notes, and snippets.

@johnryanmal
Last active February 15, 2023 23:20
Show Gist options
  • Save johnryanmal/89ae7c2c26695e640c3367ef9792a0cb to your computer and use it in GitHub Desktop.
Save johnryanmal/89ae7c2c26695e640c3367ef9792a0cb to your computer and use it in GitHub Desktop.
My custom git configuration. It contains colors, formatting, and aliases.
[push]
default = tracking
[color]
ui = auto
diff = auto
branch = auto
interactive = auto
status = auto
[pretty]
# custom ver of --oneline format
line = "%C(auto)%h%C(reset) %C(auto)%s%C(auto)%d"
nline = "\n%C(auto)%h%C(reset) %C(auto)%s%C(auto)%d"
name = "%C(auto)%s%C(auto)%d"
# lg formats taken from https://stackoverflow.com/questions/1838873/visualizing-branch-topology-in-git/34467298#34467298
lg1 = "%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)"
lg2 = "%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n %C(white)%s%C(reset) %C(dim white)- %an%C(reset)"
lg3 = "%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)%n %C(white)%s%C(reset)%n %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)"
[alias]
# graphing (see above for lg)
graph = log --graph --abbrev-commit --decorate
graph-all = graph --all
lg = lg1
lga = lga1
lg1 = graph --format=lg1
lg2 = graph --format=lg2
lg3 = graph --format=lg3
lga1 = graph-all --format=lg1
lga2 = graph-all --format=lg2
lga3 = graph-all --format=lg3
# documentation
book = !open https://git-scm.com/book/en/v2
h = help
info = help
i = info
man = help
# status
now = changes
stat = status -s
at = show HEAD -s --abbrev-commit --format=line
changes = diff HEAD^ --stat --cached
here = show HEAD
ls = graph-all --format=line
ll = log --format=line
lln = ll -n
ln = "!f() { git lln \"${1:-10}\"; }; f"
nl = !git log --format=name | nl -v 0 -n "rn"
history = whatchanged --abbrev-commit --format=nline
hist = history
# helper scripts
test = !git rev-parse 2>/dev/null
test-branch = !git rev-parse --verify 2>/dev/null >/dev/null
input = "!f() { test -p /dev/stdin && paste - || return 1; }; f"
#wrap = "!f() { eval \"$1\"; }; f"
# scripts
isrepo = !git test && echo 'true' || echo 'false'
create = "!f() { mkdir -p \"$*\"; cd \"$*\"; git first \"$*\"; }; f"
first = "!f() { echo '#' \"$*\" >> README.md; git init; git add README.md; git commit -m \"first commit\"; git branch -M main; }; git test || f"
setup = "!f() { git init; git add -A; git commit -m \"init\"; }; f"
mount = "!f() { git remote remove origin; git remote add origin \"$*\"; git branch -M main; git push -u origin main; }; f"
destroy = !rm -rf .git
new = create
# cli
cmds = "!f() { local cmd; for cmd in \"$@\"; do eval \"git ${cmd}\"; done; }; f"
# repo config
urls = remote -v
url = config remote.origin.url
fetchurl = config remote.origin.fetch
auto-fetchurl = fetchurl +refs/heads/*:refs/remotes/origin/*
pushurl = config remote.origin.pushurl
nourls = remote remove origin
nopushurl ="!f() { local url=\"$(git url)\"; git nourls; git url \"$url\"; }; f"
repos = urls
from = url
to = "!f() { test -n \"$1\" && git pushurl \"$1\" || git pushurl || git url; }; f"
repo = !git from | xargs open
pushrepo = !git to | xargs open
source = from
destination = to
src = source
dest = destination
user = config --get --global user.name
email = config --get --global user.email
github = !echo "https://github.com/$(git user)"
profile = !git github | xargs open
hub = github
gh = github
# caching
delta = add -u
track = add .
add-all = add -A
a = add
aa = add-all
dt = delta
tr = track
hard-reset = reset --hard
stage-all = add --all
nostage = reset HEAD -- #from git book
upstage = delta
destage-all = uncache
#destage = uncache
cache = add .
cache-all = cache --all
uncache = rm --cached --quiet
uncache-all = uncache -r .
nocache = uncache-all -f
recache = !git nocache && git cache
warn = clean -dn
clear = clean -df
# retreive head
head = show --abbrev-commit
# commits
commit-m = "!f() { git commit -m \"$*\"; }; f"
amend = commit --amend --allow-empty
amend-m = "!f() { git amend -m \"$*\"; }; f"
cm = commit
cmm = commit-m
as = show -s --pretty=format:%B
amend-as = "!f() { test -n \"$*\" && git amend-m \"$@\" || git amend -m \"$(git as)\"; }; f"
save = !git delta && git amend-as
save-as = !git delta && git commit-m
save-all = !git track && git save
save-all-as = !git track && git save-as
s = save
sa = save-as
sal = save-all
sala = save-all-as
# get remote
download = fetch --all
update = pull --all
install = !git download && git update
dl = download
up = update
inst = install
# sync remote
read = pull origin
write = push origin
retrieve = read main
publish = write HEAD
synchronize = retrieve --ff-only
chain = retrieve --rebase
unify = retrieve --no-rebase
forward = !git synchronize && git publish
stream = !git stack && git publish
link = !git unify && git publish
autoread = read --autostash
r = read
w = write
ret = retrieve
pub = publish
sync = synchronize
chn = chain
ufy = unify
fw = forward
strm = stream
lnk = link
# DANGER sync remote
force-pull = "!f() { test \"$#\" -le 1 && git force-pull-local \"$@\" || git force-pull-remote \"$@\"; }; f"
force-pull-local = "!f() { git fetch \"$@\" && git reset --hard; }; f"
force-pull-remote = "!f() { git fetch \"$1\" \"${@:2}\" && git reset --hard \"${1}/${@:$#}\"; }; f"
force-read = force-pull origin
force-retrieve = force-read main
force-push = push -f
force-write = force-push origin
force-publish = force-write HEAD
overwrite = force-write
f-pull = force-pull
f-push = force-push
f-read = force-read
f-write = force-write
f-ret = force-retrieve
f-pub = force-publish
# branching
branches = branch -l
nobranch = branch -D
on-branch = rev-parse --abbrev-ref HEAD
on = "!f() { test -n \"$*\" && git checkout \"$*\" || git on-branch; }; f"
follow = "!f() { git branch --set-upstream-to=\"$1\"; }; f"
subscribe = !git follow "origin/$(git on-branch)"
sub = subscribe
# navigation
load = checkout
reload = checkout .
l = load
go = "!f() { git test-branch \"$*\" && git checkout \"$*\" || git checkout -b \"$*\"; }; f"
goto = checkout
split = checkout -b
b = branch
attach = switch -
detach = switch --detach
back = checkout HEAD^
main = go main
# merging
unrebase = rebase --abort
norebase = rebase --quit
unmerge = merge --abort
nomerge = merge --quit
# stashing
stashes = stash list
unstash = stash pop
nostash = stash clear
stash-all = stash --all
temp = !git add --all && git stash
temps = stashes
untemp = unstash
notemp = nostash
tmp = temp
# path helpers
root = rev-parse --show-toplevel
where = rev-parse --absolute-git-dir
which = where
path = root
dir = where
pathname = "!f() { echo \"$(git path)\" \"$@\" | sed s@' '@'/'@g; }; f"
dirname = "!f() { echo \"$(git dir)\" \"$@\" | sed s@' '@'/'@g; }; f"
gitconfig = gitconfig-local
gitconfig-global = !echo "~/.gitconfig"
gitconfig-local = !echo "$(git dirname config)"
gitignore = !echo "$(git pathname .gitignore)"
# vscode
vsconfig = !code "$(git gitconfig)"
vsconfig-local = !code "$(git gitconfig-local)"
vsconfig-global = !code "$(git gitconfig-global)"
vsignore = !code "$(git gitignore)"
conf = vsconfig
igno = vsignore
rc = vsconfig-global
# config
unconfig = config --unset
noconfig = config --unset-all
local = config --local
unlocal = unconfig --local
nolocal = noconfig --local
global = config --global
unglobal = unconfig --global
noglobal = noconfig --global
unknown = config
ununknown = unconfig
nounknown = noconfig
config-scopes = config -l --show-scope --name-only
config-scope = "!f() { git configs | sed -n s/\"^${*}\t\"/\"${*} \"/p; }; f"
configs = config-scopes
locals = config-scope local
globals = config-scope global
unknowns = config-scope unknown
ignore = "!f() { echo \"$@\" >> \"$(git gitignore)\"; git recache; }; f"
unignore = "!f() { local gitignore=\"$(grep -v "^${*}$" "$(git gitignore)")\"; echo \"$gitignore\" > $(git gitignore); git recache; }; f"
alias = "!f() { git global \"alias.${1}\" \"${*:2}\"; }; f"
unalias = noalias
noalias = "!f() { git noglobal \"alias.${1}\"; }; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment