Skip to content

Instantly share code, notes, and snippets.

@crunchie84
Created April 21, 2020 12:48
Show Gist options
  • Save crunchie84/050bca4670f68fb1dd0891bcf3611848 to your computer and use it in GitHub Desktop.
Save crunchie84/050bca4670f68fb1dd0891bcf3611848 to your computer and use it in GitHub Desktop.
git alias for the win 💪
#
# Include this in your own .gitconfig by using the
# [include] directive with the path to this file
#
# [include]
# path = ~/.gitconfig.aliases
#
# If you don't have any existing includes, you can add this via the following command
#
# git config --global include.path ~/.gitconfig.aliases
#
[alias]
abort = rebase --abort
aliases = "!git config -l | grep alias | cut -c 7-"
amend = commit -a --amend
# Deletes all branches merged specified branch (or master if no branch is specified)
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs git branch -d; }; f"
# Switches to specified branch (or master if no branch is specified), runs git up, then runs bclean.
bdone = "!f() { git checkout ${1-master} && git up && git bclean ${1-master}; }; f"
# Lists all branches including remote branches
branches = branch -a
browse = !git open
# Lists the files with the most churn
churn = !git --no-pager log --name-only --oneline | grep -v ' ' | sort | uniq -c | sort -nr | head
cleanup = clean -xdf -e *.DotSettings* -e s3_keys.ps1
# Stages every file then creates a commit with specified message
cm = !git add -A && git commit -m
co = checkout
cob = checkout -b
# Show list of files in a conflict state.
conflicts = !git diff --name-only --diff-filter=U
cp = cherry-pick
delete = branch -d
# Discard changes to a file
discard = checkout --
ec = config --global -e
find = "!git ls-files | grep -i"
graph = log --graph -10 --branches --remotes --tags --format=format:'%Cgreen%h %Creset• %<(75,trunc)%s (%cN, %cr) %Cred%d' --date-order
grep = grep -Ii
hist = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
history = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
# Shows the commit message and files changed from the latest commit
latest = "!git ll -1"
# Display tree-like log, because default log is a pain…
lg = log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ad)%Creset'
lost = fsck --lost-found
# Moves a set of commits from the current branch to another
migrate = "!f(){ CURRENT=$(git symbolic-ref --short HEAD); git checkout -b $1 && git branch --force $CURRENT ${3-$CURRENT@{u}} && git rebase --onto ${2-master} $CURRENT; }; f"
open = "!f(){ URL=$(git config remote.origin.url); open ${URL%.git}; }; f"
pr = "!f(){ URL=$(git config remote.origin.url); open ${URL%.git}/compare/$(git rev-parse --abbrev-ref HEAD); }; f"
publish = "!f() { git push origin $1 && git push drafts :$1 && git browse }; f"
rba = rebase --abort
rbc = "!f(){ git add -A && git rebase --continue; }; f"
re = "!f(){ git fetch origin && git rebase origin/${1-master}; }; f"
remotes = remote -v
restore = "!f(){ git add -A && git commit -qm 'RESTORE SAVEPOINT'; git reset $1 --hard; }; f"
ri = "!f(){ git fetch origin && git rebase --interactive origin/${1-master}; }; f"
save = !git add -A && git commit -m 'SAVEPOINT'
set-origin = remote set-url origin
set-upstream = remote set-url upstream
st = status
stashes = stash list
sync = !git pull --rebase && git push
undo = reset HEAD~1 --mixed
# Unstage a file
unstage = reset -q HEAD --
up = !git pull --rebase --prune $@ && git submodule update --init --recursive
wip = commit -am "WIP"
wipe = "!f() { rev=$(git rev-parse ${1-HEAD}); git add -A && git commit --allow-empty -qm 'WIPE SAVEPOINT' && git reset $rev --hard; }; f"
[core]
# VSCode
editor = code --wait
# Don't consider trailing space change as a cause for merge conflicts
whitespace = -trailing-space
[diff]
# Use better, descriptive initials (c, i, w) instead of a/b.
mnemonicPrefix = true
# Show renames/moves as such
renames = true
# When using --word-diff, assume --word-diff-regex=.
wordRegex = .
# Display submodule-related information (commit listings)
submodule = log
# Use VSCode as default diff tool when running `git diff-tool`
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment