Skip to content

Git Aliases

Austin Horstman edited this page Nov 9, 2021 · 10 revisions

Git Aliases

Random

random dad joke if typo on git add

dad = !curl https://icanhazdadjoke.com/ && echo 

Git Flow Operations

add file, add and commit all, add patch

a = add
ac = !git add . && git commit -am
ap = add -p

commit, commit all, commit all ?, amend commit

c = commit --verbose
ca = commit -a --verbose
cam = commit -a -m
m = commit --amend --verbose
cm = !git add -A && git commit -m

checkout, create and checkout new branch, checkout master, checkout develop

co = checkout 
cob = checkout -b
com = checkout master
cod = checkout develop

sync and cleanup with remote

up = !git pull --rebase --prune $@ && git submodule update --init --recursive 

creates a savepoint commit

save = !git add -A && git commit -m 'SAVEPOINT' 

creates a wip commit

wip = !git add -u && git commit -m "WIP" 

modify current commit

amend = commit -a --amend 

go back a single commit

undo = reset HEAD~1 --mixed 

stash and list stashes

st = stash
stl = stash list

diff, diff stat, diff cached

d = diff
ds = diff --stat
dc = diff --cached

reset working directory discarding/removing all files

res = !git reset --hard 

pushes current branch

done = !git push origin HEAD 

create a silent savepoint commit and reset back a commit

wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard 
bclean = "!f() { DEFAULT=$(git default); git branch --merged ${1-$DEFAULT} | grep -v " ${1-$DEFAULT}$" | xargs git branch -d; }; f" 
bdone = "!f() { DEFAULT=$(git default); git checkout ${1-$DEFAULT} && git up && git bclean ${1-$DEFAULT}; }; f"

branch delete: This checks out your local master branch and deletes all local branches

that have already been merged to master

brd = !sh -c \"git checkout master && git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d\"

branch delete here: Deletes all local branches that have already been merged to the branch

that you're currently on

brdhere = !sh -c \"git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d\"

push everything to remote

pushitgood = push -u origin --all

push current to remote

po = !echo 'Ah push it' && git push origin && echo 'PUSH IT REAL GOOD'

add current branch to remote ??

rao = remote add origin
mergetest = "!f(){ git merge --no-commit --no-ff \"$1\"; git merge --abort; echo \"Merge aborted\"; };f "

rebase interactive aggainst master

ria = !git rebase -i 'git merge-base HEAD master'

History / Listing

one-line log

l = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short 

pretty formatted git log

lg = !git log --pretty=format:\"%C(magenta)%h%Creset -%C(red)%d%Creset %s %C(dim green)(%cr) [%an]\" --abbrev-commit -30 

list aliases

la = "!git config -l | grep alias | cut -c 7-" 

list branches sorted by last modified

lb = "!git for-each-ref --sort='-authordate' --format='%(authordate)%09%(objectname:short)%09%(refname)' refs/heads | sed -e 's-refs/heads/--'"

display current branch

b = rev-parse --abbrev-ref HEAD 

Aside from providing one-line logs, it also shows the branching in/out

hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short

?

ec = config --global -e

forced pull: You have a local branch (e.g. for reviewing), but someone else did a forced push

update on the remote branch. A regular git pull will fail, but this will just set

the local branch to match the remote branch. BEWARE: this will overwrite any local

commits you have made on this branch that haven't been pushed.

pullf = !sh -c \"git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)\"

pull only the current branch and dont update refs of all remotes

pullhead = "!f() { \
local b=${1:-$(git rev-parse --abbrev-ref HEAD)}; \
git pull origin $b; \
}; f" 

blow up local branch and repull from remote

smash = "!f() { \
local b=${1:-$(git rev-parse --abbrev-ref HEAD)}; \
echo 'Are you sure you want to run this? It will delete your current '$b'.'; \
read -p 'Enter to continue, ctrl-C to quit: ' response; \
git checkout master; \
git branch -D $b; \
git fetch origin $b; \
git checkout $b; \
}; f"

rebase current branch off master

rbm = "!f() { \
local b=${1:-$(git rev-parse --abbrev-ref HEAD)}; \
echo 'Are you sure you want to run this? It will delete your current '$b'.'; \
read -p 'Enter to continue, ctrl-C to quit: ' response; \
git checkout master; \
git pull origin master; \
git checkout $b; \
git rebase master; \
}; f"

rebase current branch off develop

rbd = "!f() { \
local b=${1:-$(git rev-parse --abbrev-ref HEAD)}; \
echo 'Are you sure you want to run this? It will delete your current '$b'.'; \
read -p 'Enter to continue, ctrl-C to quit: ' response; \
git checkout develop; \
git pull origin develop; \
git checkout $b; \
git rebase develop; \
}; f"
Clone this wiki locally