Skip to content

Instantly share code, notes, and snippets.

@ErisDS
Last active November 12, 2024 20:03
Show Gist options
  • Save ErisDS/122b158774b7394f86a6bdb5c3aab7f9 to your computer and use it in GitHub Desktop.
Save ErisDS/122b158774b7394f86a6bdb5c3aab7f9 to your computer and use it in GitHub Desktop.
Git Aliases
# NOTE on remote naming:
# I clone the original (upstream) repo first, which means that's set to "origin"
# and then if I want to use my own fork, I clone it using `git remote add fork [email protected]:ErisDS/...
# which means my fork is called... "fork".
# I always found origin and fork made more sense as names...
# this is why we have support for a GHOST_UPSTREAM env var in all of our older tooling like gstenv,
# as it's personal taste between that and upstream & origin,
[alias]
# OLD :D
master = !git checkout master && git fetch origin && git pull --rebase origin master
# like `yarn main` but works everywhere p much
main = !git checkout main && git fetch origin && git pull --rebase origin main
# predates being able to set autostash as a default. I no longer use this alias
prom = pull --rebase origin main --autostash
# many shorthand, much less carpal tunnel, wow
st = status
ci = commit
rs = restore --staged
co = checkout
br = branch
cp = cherry-pick
df = diff
who = shortlog -s -n --no-merges
fc = show --name-only
sub = submodule update --init
# cuz I always typod this
submodules = submodule
# See details of the last commit with `git wc -1`
wc = whatchanged
# Undo your last commit (uncommits, but doesn't lose the changes
undo = reset HEAD~1
# Add the current stashed changes to your previous commit, for you know, typos and shit :D
fix = commit --amend --no-edit
# useful for rebasing commits later
# use `git fixup [commit ref]` to mark a commit as fixing an earlier commit in your history
# git rebase -i --autosquash will then clean your history
# I really should have a shorthand for git rebase -i --autosquash!
cf = commit --fixup
fixup = commit --fixup
# Many log commands. I mostly use the first one!
lo = log --pretty=tformat:'%C(cyan)%h%Creset: %s %C(magenta)%an %Cgreen(%cr)%Creset'
lf = log --pretty=tformat:'%C(cyan)%h%Creset: %s %C(magenta)%an %Cgreen(%cr)%Creset' --follow
l5 = log --pretty=tformat:'%C(cyan)%h%Creset: %s %C(magenta)%an %Cgreen(%cr)%Creset' -5
ll = log --no-merges --pretty=tformat:'%C(cyan)%h%Creset: %C(yellow reverse)%d%Creset %s %C(magenta)%an%Creset'
lg = log --graph --all --pretty=format:'%C(cyan)%h %C(auto)%d %s %C(bold blue)<%an> %Cgreen(%cr)%Creset' --abbrev-commit
g = log --graph --pretty=tformat:'%C(cyan)%h%Creset: %C(yellow reverse)%d%Creset %s %C(magenta)(%an, %cr)%Creset'
gg = log --graph --oneline --all --decorate --topo-order
clg = log --graph --no-merges --pretty=tformat:'%h %d %s %an'
cll = log --no-merges --pretty=tformat:'%h %d %s %an'
cl = log --no-merges --pretty=tformat:'* [%h](https://github.com/TryGhost/Ghost/commit/%h) %s - %an'
# This will show you the reflog in a more readable format than just `git reflog`
saveme = reflog --pretty='%cd %h %gd %gs'
# really old things I used to use in the early days and don't remember anymore
contribs = "!f() { git shortlog -sn --no-merges $1.. | awk '{printf (\"%s %s, \", $2, $3)}'; }; f"
qc = "!f() { git commit -m $1 -m '[ci skip]' && git push fork; }; f"
# SUPER MAGIC command to see what all your local branches are :D
branches = "!f () { git branch | xargs -L1 -I _ sh -c 'echo _; git l5 _'; }; f"
# requires config per repo that you want this to work for
# in .git/config
# under [remote "origin"]
# fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
pr = "!f() { git fetch origin pull/$1/head:pr-$1; git co pr-$1; }; f"
# replaces the need for an alias to pull and rebase
[pull]
rebase = true
[rebase]
autoStash = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment