Skip to content

Instantly share code, notes, and snippets.

@bskinn
Last active June 10, 2024 00:37
Show Gist options
  • Save bskinn/fdeff46d22340f6ad830ecc32afecd67 to your computer and use it in GitHub Desktop.
Save bskinn/fdeff46d22340f6ad830ecc32afecd67 to your computer and use it in GitHub Desktop.
Various git aliases
# [alias] has been improved to where you don't need explicit sh calls.
# And, as long as you don't need argument processing, you can just
# alias to whatever you would type after 'git'.
[alias]
# Pretty-printed tree view of the commit history
# Can't remember where I found the incantation
logtree = log --graph --all --oneline --decorate=full
# Same as logtree, but adds timestamps for each commit
# Useful with less's `&` command (regex line filtering) to only show commits on a given date
logtreed = log --graph --all --oneline --decorate=full --pretty=format:'%C(auto)%h%d (%cI) %s'
# Show the timestamps for all of the commits where a file was modified
# git recipe from https://stackoverflow.com/a/2390382/4376000
# bash-function alias syntax from https://www.atlassian.com/blog/git/advanced-git-aliases
filedates = "!f() { git log --follow --format='%h %ad %s' --date default -- $1; }; f"
# Mimics GitHub's `/compare/`. Pass it a double- or triple-dot spec between two
# refs of interest. Defaults to the diff of `main...HEAD`
cmp = "!f() { git log "'"'"${1:-main...HEAD}"'"'" --graph --oneline --decorate=full --boundary; }; f"
# Shortcut for the incantation needed to consolidate fixup commits
fixup = rebase -i --autosquash
# Publish the current branch to remote.
# First (optional) arg is remote to push to, if other than origin
pub = "!f() { git push -u ${1:-origin} $( git rev-parse --abbrev-ref HEAD ); }; f"
# Delete (push null to) a remote reference.
# First (required) argument is the reference to delete.
# Second (optional) argument is the remote to operate on.
remdel = "!f() { git push ${2:-origin} "'"'":${1:-non-existent-thing}"'"'"; }; f"
# Short aliases for common things
lt = logtree
ltd = logtreed
a = add
c = commit
k = checkout
kb = checkout -b
km = checkout main
d = diff
s = status
b = branch
bv = branch -vv
f = fetch
fp = fetch -p
p = pull
pp = pull -p
m = merge
mnoff = merge --no-ff
mffo = merge --ff-only
h = push
rso = remote show origin
rsu = remote show upstream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment