Created
April 28, 2022 17:03
-
-
Save snekse/ea652851a1156cc2fbd253309699e750 to your computer and use it in GitHub Desktop.
git alias commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
######################################## | |
# Config commands | |
######################################## | |
editConfig = "!code ~/.gitconfig" | |
# setAuthor "Firstname Lastname" "email@gmail.com" | |
setAuthor = "!f(){ git config user.name $1 && git config user.email $2; }; f" | |
# setEmail "email@gmail.com" | |
setEmail = "!f(){ git config user.email $1; }; f" | |
######################################## | |
# Commit commands | |
######################################## | |
amend = commit -a --amend | |
######################################## | |
# Branching and Checkout commands | |
######################################## | |
branches = branch -ra | |
co = checkout | |
cob = checkout -b | |
cop = "!f() { git co $1 && git pull; }; f" | |
makeb = "!f() { git cob $1 && git branch --force $2 origin/$2; }; f" | |
findb = "!f(){ git branches | grep $1; }; f" | |
st = status -sb #Short status w/ branch info | |
echoStatus = "!f(){ pwd && git status -sb && echo; }; f" | |
recent = for-each-ref --count=10 --sort=-committerdate refs/heads/ --format="%(refname:short)" | |
######################################## | |
# Pull & Fetch commands | |
######################################## | |
pr = pull --rebase | |
fetchup = fetch upstream | |
######################################## | |
# Rebase commands | |
######################################## | |
# Push after a pulling remote rebase | |
pullrp = !git pr && git push | |
prp = !git pullrp #pullrp alias | |
pullrsup = !git pr && git submodule update --recursive && git push | |
# Rebase with a different branch - could be remote, could be local | |
# USAGE: rebaseWith develop -OR- rebaseWith origin/release/4.1.2 | |
# Checks out the local version of $1, pulls the latest, co original branch, rebase with $1 | |
rebaseWith = "!f(){ git cop $1 && git rbPrevWith $1; }; f" | |
rbPrevWith = "!f(){ git co - && git rebase $1; }; f" | |
# Rebase with upstream - requires a remote named upstream | |
# e.g. git remote add upstream git@github.com:snekse/dotfiles.git | |
reUp = "!f(){ git cop $1 && git fetchup && git rebase upstream/$2; }; f" | |
rebaseWithUpstream = "!f(){ git cop $1 && git fetchup && git rebase upstream/$1 && git rbPrevWith $1; }; f" | |
######################################## | |
# Push commands | |
######################################## | |
# Force creating the new remote branch | |
pushUpNew = push -u origin HEAD | |
######################################## | |
# Diff | |
######################################## | |
diffw = diff -w | |
worddiff = diff --word-diff | |
######################################## | |
# Logging commands | |
######################################## | |
overview = log --all --since='10 days' --oneline --no-merges | |
recap = !git log --all --oneline --no-merges --author=${1-$(git config user.email)} | |
today = !git log --all --since=00:00:00 --oneline --no-merges --author=${1-$(git config user.email)} | |
whatDidIDo = "!f(){ git log --all --no-merges --author=$(git config user.email); }; f" | |
changelog = "!f(){ log --oneline --no-merges $1..$2; }; f" ## changelog 1257b95 HEAD ## | |
lc = log --pretty=format:"%C(yellow)%h" --decorate | |
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate | |
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat | |
lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short | |
lg = 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 | |
lg1 = 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 | |
graph = log --graph --all --decorate --stat --date=iso | |
######################################## | |
# WIP/Stash commands | |
######################################## | |
sl = stash list | |
sa = stash apply | |
ss = stash save | |
undo = reset HEAD~1 --mixed | |
# Rebase commits, clean up deleted branchs, manage git submodules if there are any | |
up = !git pullrp $@ && git submodule update --init --recursive | |
wip = commit -am "WIP" | |
# When you think all of your code charges are mostly garbage, but we want to be able to go back if needed | |
trash = !git add -A && git commit -qm 'TRASH RESTART SAVEPOINT' && git reset HEAD~1 --hard | |
trashrestore = "!f(){ git add -A && git commit -qm 'RESTORE SAVEPOINT'; git reset $1 --hard; }; f" | |
######################################## | |
# History commands | |
######################################## | |
deletedWhen = rev-list -n 1 HEAD -- ## <file_path> e.g. git deletedWhen src/java | |
find = log --oneline --name-status -i --grep | |
lastMatching = "!f(){ git log --pretty=format:'%C(yellow)%h%Cred%d %Creset%s%Cblue [%cn]' --decorate -1 --grep=$1; }; f" | |
lastMatchingCommit = "!f(){ git log --pretty=format:'%C(yellow)%h' --decorate -1 --grep=$1; }; f" | |
######################################## | |
# Client-centric commands - update as needed | |
######################################## | |
dev = !git co develop | |
devUp = !git cop develop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment