Skip to content

Instantly share code, notes, and snippets.

@piotros
Last active February 17, 2024 14:36
Show Gist options
  • Save piotros/2edf6736c1ad65c31a0d4666f53828ad to your computer and use it in GitHub Desktop.
Save piotros/2edf6736c1ad65c31a0d4666f53828ad to your computer and use it in GitHub Desktop.
Some useful git aliases and settings that I use
[user]
useConfigOnly = true
# [includeIf "gitdir:~/Projects/company1/"]
# path = ~/Projects/company1/.gitconfig
[alias]
# add all
aa = add .
# branches list
bl = branch
# branches list long
bll = branch -vv
# branch name
bn = "!git rev-parse --abbrev-ref HEAD"
# checkout
c = checkout
# checkout bugfix
cb = !sh -c \"git checkout bugfix/$1\" -
# checkout develop
cd = checkout develop
# checkout feature
cf = !sh -c \"git checkout feature/$1\" -
# checkout hotfix
ch = !sh -c \"git checkout hotfix/$1\" -
# checkout refactor
cr = !sh -c \"git checkout refactor/$1\" -
# checkout new bugfix
cnb = !sh -c \"git checkout -b bugfix/$1\" -
# checkout new feature
cnf = !sh -c \"git checkout -b feature/$1\" -
# checkout new hotfix
cnh = !sh -c \"git checkout -b hotfix/$1\" -
# checkout new refactor
cnr = !sh -c \"git checkout -b refactor/$1\" -
# checkout master
cm = checkout master
# commit staged files
csf = !sh -c \"git commit -m '$1'\" -
# commit amend
cam = commit --amend --no-edit
# commit amend with edit
camwe = commit --amend
# diff
dff = diff --color-words
# diff cached
dffc = diff --color-words --cached
# fetch
f = fetch
# find branch
fb = !sh -c \"git branch -a --list *'$1'*\" -
# list aliases
la = "!git config -l | grep alias | cut -c 7-"
# log
lg = log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=relative
# log with files
lgf = log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=relative --numstat
# merge master
mm = merge master --no-ff
# merge origin master
mom = merge origin/master --no-ff
# publish
pub = "!git push -u origin $(git bn)"
# push force
puf = push --force-with-lease
# rebase abort
rea = rebase --abort
# rebase continue
rec = rebase --continue
# rebase master
rem = rebase -i master
# rebase skip
res = rebase --skip
# remove bugfix branches
rmbb = "!git branch -d `git branch | grep -E 'bugfix/*'`"
# remove feature branches
rmfb = "!git branch -d `git branch | grep -E 'feature/*'`"
# remove hotfix branches
rmhb = "!git branch -d `git branch | grep -E 'hotfix/*'`"
# remove refactor branches
rmrb = "!git branch -d `git branch | grep -E 'refactor/*'`"
# remove branches without remote
rmbwr = "!git fetch -p && for branch in `git branch -vv --no-color | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done"
# status
s = status
# short status
ss = status -s
# stash apply
sta = "!f() { index=${1-0}; git stash apply stash@{$index}; }; f"
# stash drop
std = "!f() { index=${1-0}; git stash drop stash@{$index}; }; f"
# stash diff
stdff = "!f() { index=${1-0}; git stash show -p --color-words stash@{$index}; }; f"
# stash list
stl = stash list
# stash pop
stp = "!f() { index=${1-0}; git stash pop stash@{$index}; }; f"
# stash rename ($1=msg, $2=index)
str = "!_() { index=${2-0}; rev=$(git rev-parse stash@{$index}) && git stash drop stash@{$index} || exit 1 ; git stash store -m \"$1\" $rev; }; _"
# stash save
sts = !sh -c \"git stash save -u '$1'\" -
# stash show files
stsf = "!f() { index=${1-0}; git stash show stash@{$index}; }; f"
# tree
tree = log --graph --decorate --pretty=oneline --abbrev-commit
# undo
undo = reset HEAD~1 --mixed
# where is commit
wic = !sh -c \"git branch -a --contains '$1'\" -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment