Skip to content

Instantly share code, notes, and snippets.

@bernardoadc
Last active March 22, 2022 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bernardoadc/08c2aeb13685b7ca923fcb1e014bea54 to your computer and use it in GitHub Desktop.
Save bernardoadc/08c2aeb13685b7ca923fcb1e014bea54 to your computer and use it in GitHub Desktop.
GIT Alias
[alias]
ae = !"$(git ed) \"$(git ad)$1.gitalias\" #" # edit a given .gitalias file (or main one)
al = !"afs=($(git afs)) && for n in \"${!afs[@]}\"; do echo \"$n - ${afs[$n]}\"; done && read n && trap 'return' SIGINT && $(git ed) ${afs[$n]} #" # list all .gitalias files + choose one to edit
af = !"git config --global --get-all include.path | grep "/.gitalias" #" # pq grep -l ".gitalias" $(git config --global --get-all include.path) funciona?
afs = !"git config --global --get-all include.path #"
ad = !"echo $(git af) | head -c-10"
alias-sync = !"git -C \"$(git ad)\" pull origin master && git -C \"$(git ad)\" push origin master #"
alias = ae
as = !"git alias-sync #"
au = !"git -C \"$(git ad)\" ac \"$1\" && git as #"
av = !"less $(git af)" # quick view
ah = !"grep \" $1 = \" $(git af) | sed 's/^//;s/ = / = /;s/# /# /;s/$//' #" # alias help / quick alias view
ahx = !"grep --color=always \"$1\" $(git af) #" # alias help extended - search all
aq = !"grep -c \" = \" $(git af) #" # alias count (quantity)
ar = !"git -C \"$(git ad)\" rv #"
ai = !"git config --global include.path \"$1\""
cor = "echo ' TESTE '" # sem "!"!!
# cor2 = "echo '${Red}TESTE '" # sem "!"!!
# src = !"source '$(git ad)colors' | git cor2" # ou .
# configs
where = !"echo $GIT_EXEC_PATH #"
bash = !"$($GIT_EXEC_PATH | head -c-24)/git-bash #"
#cmd =
sh = !"$1 #" # usar com aspas = 1o argumento
repl = !gitrepl
cls = !clear
cf = config --global -e # manter no .gitconfig do user?
cfl = config --list --show-origin
vscode = config --global core.editor "code" # in Mac: "install code command in path" on command pallete
ed = config --global --get core.editor
# user
winuser = config --global credential.helper wincred
#new-pw = !"f() { git credential approve; url=$1; password=$2; ;}; f" #!git credential reject && git credential fill && git credential approve .. fill é mais um get, apesar de salvar tb. pra trocar poderia usar só approve. nao funfa, anyway
#new-pw = #!git credential-wincred erase && git credential-wincred get && git credential-wincred save # deveria ajudar mas n funfa igual, nao recebe param url..
win-del-pw = !cmdkey /delete:git:$(git remote get-url ${1:-origin})
wincred = !rundll32 keymgr.dll,KRShowKeyMgr #ou 'Control Userpasswords2'
credfile = config credential.helper store --file # <path/.git-credentials>
# refs
toproot = rev-parse --git-dir # for submodules
root = rev-parse --show-toplevel
nextref = !"f() { git log --reverse --ancestry-path --pretty=%H $1..HEAD | head -${2:-1} | tail -1; }; f" # oposto de ref~1
prevref = !"f() { git rev-parse $1~$2; }; f"
# repo
i = init
ib = init --bare
# remotes
r = remote
rl = r
ra = !"git remote add ${2:-origin} $1 #" <url> <remote-name>
rn = remote rename
rv = remote -v
ru = !"git remote get-url ${1:-origin} #" # <remote-name>
ruu = !"git remote set-url ${2:-origin} $1 #"
rs = remote show # <remote-name #view all branches and refs local vs remote
rupw = !"f() { find=://; ru=$(git ru $3); echo ${ru/$find/$find$1:$2@};}; f" # <user> <pw> <remote> URL com user e pw #TODO: replace @ do email com %40
#rb = ... # remote branches
rd = !"git remote remove ${1:-origin} #" # <name>
# submodules
sma = submodule add
smw = submodule init # <Which-list-of-submodules-of-interest (space sep)>
sml = submodule--helper list
sms = submodule status
smu = submodule update # updates submodules selectec / all
smn = git submodule update --init # <submodule-path # pull new submodule
# commit
aa = add -A
un = restore --staged # <files> # unstage
uns = rm -r --cached # <files> # unstage
uns = rm -r --cached . # <files> # unstage
st = status
stv = diff # ver o que foi modificado desde ultimo commit
wc = status -v # ver exatamente o que vai ser commitado (will commit)
ac = !git aa && git cm
aca = !git aa && git amend
c = commit # detalhar a msg no editor
cm = commit -m # <message> -m "$2"
ca = !git amend
amend = commit --amend -m # <message>
o = !"git rebase -i $1^ #" # <ref> (organize, order)
or = rebase -i --root
ob = !"git rebase -i $(git bo)" # rebase whole branch
crn = rebase -i HEAD@{1} # (rename)
clear = reset --hard # discard all changes
undo = reset HEAD@{1} # undo commit
u = undo
z = reset --soft HEAD@{1}
zz = reset ORIG_HEAD # undo the undo
cancel = revert --no-commit # <sha>
# stash
# tds variaçoes? ss, si, su, ssi, ssu, siu, sa = ssiu
ss = stash push -u --no-keep-index -m # só unstaged = tudo menos o q ta no stage/index + untracked (pegou index!)
si = !"git stash push -k && git stash push && git stash pop" # apenas index
sa = stash push -u -k -m # tudo: stage/index, unstaged, untracked (pegou index!)
#saa = stash push -u -a #all nao usar! inclui arquivos ignorados
sk = stash push --keep-index -m # 1o stage o que quiser manter
sb = !"git stash branch \"STASH_$(git sn ${1:-0} | tr [:blank:] '_')\" stash@{${1:-0}} && git ac \"from stash\"" # save stash as branch
#sba = !"$(for sha in $(git rev-list -g stash); do git sb $sha:refs/heads/stash_$sha; done)" # save all stashes as branches
sl = stash list
sn = !"git --no-pager stash list | head -n $(($1 + 1)) | tail -n 1 | cut -d: -f3 | cut -b 2- #" # pega nome da stash
slu = !"git rev-list -g stash@{${1:-0}} | git rev-list --stdin --max-parents=0 | xargs git show --stat #" #view list of stashes with untracked files
sv = stash show -p # <stash@{n}> v = view
svt = !"git stash show stash@{${1:-0}}: #" # <n> vt = view stash tree
svu = !"git show stash@{${1:-0}}^3 #" # <n> vu = view untracked files
svuf = !"git show stash@{${2:-0}}^3:$1 #" # <file> <n> vu = view untracked files
svul = !"git ls-tree -r stash@{${1:-0}}^3 --name-only #" # <n> vu = view untracked files
svut = !"git stash show stash@{${1:-0}}^3: #" # <n> vut = view untracked files stash tree
sp = stash pop #stash@{n}
sd = stash drop #stash@{n}
# sf = !"git checkout stash@{${2:0}} -- $1 #" #<filename> <nth-stash> # tira do stash só o arquivo
sf = !"git restore -s stash@{${2:-0}} -- $1 #" #<filename> <nth-stash> # tira do stash só o arquivo (overwrites!)
snf = !"git show stash@{${3:-0}}:$1 > $2 #" #<filename> <newfile> <nth-stash> # tira do stash só o arquivo, com novo nome
sfd = !"git diff stash@{${2:-0}}^1 stash@{${2:-0}} -- $1 | git pav #" #<filename> <nth-stash> # tira do stash só a diff o arquivo e visualiza
# reverte stash apply: git stash show -p | git apply --reverse
# msg: -- "msg"
# patch
pai = !"git wc2 > cached.diff"
pac = !"git format-patch -${2:-1} $1 $3 #" #<sha> <n> <nome.patch> criar patch de commit especifico (arq opcional, mas nome fica igual). -1 = -n = qntos commits a partir do sha
pab = !"git format-patch $1 --stdout > $2 #" #<branch> <nome.patch> criar patch com ultimos commits em outro branch:
pad = !"git show -p --format=email $1 > $1.patch && git df $1 -p --stat >> $1.patch #" #<sha> criar patch a partir de diff (git show $1 deveria criar já no formato de patch??)
paa = !"git apply $1 #" #<nome.patch> aplicar
pav = !"git apply --stat $1 #" #<nome.patch> apenas olhar o que tem dentro de um patch
pat = !"git apply --check $1 #" #<file.patch> testar um patch before applying it
paf = !"git apply --reject $1 #" #<file.patch> ver o que falhou num patch
pafv = !"git apply -v $1 #" #<file.patch> ver o que falhou, verbose
par = !"git apply -R $1 #" #<nome.patch> aplicar reverso (= revert mas de um diff)
# pull & push
f = !"git fetch ${1:-origin} `git bn` #"
fa = !"git fetch ${1:-origin} +refs/heads/*:refs/heads/* #" # fetch all
fc = !"git fetch ${1:-origin} ${2:-$(git bn)} && echo 'BEHIND' && git lg ${2:-$(git bn)}..${1:-origin}/${2:-$(git bn)} && echo 'AHEAD' && git lg ${1:-origin}/${2:-$(git bn)}..${2:-$(git bn)} #" # <remote> <remote-branch-name> # fetch compare
fd = !"git lg $1..$2 #" # <branch1> <branch2> # fetch diff
fb = !"git fetch ${2:-origin}/$1 #" # fetch another branch
fr = !"git rebase ${2:-origin}/$1 #" # <branch> will apply to current branch
fm = !"git merge --ff-only ${2:-origin}/$1 #" # <branch> will apply to current branch
pl = !"git pull -r ${1:-origin} `git bn` #" # pull apenas com rebase, sem merge
plf = !"git pull --ff-only ${1:-origin} `git bn` #" # pull apenas sem merge, mas ff (apenas se nao houve avanço local. Senao, obrigatorio rebase ou merge com commit)
plm = !"git pull ${1:-origin} `git bn` #" # pull normal, com possivel merge
#pla = !"git branch -r | grep -v \"\->\" | while read remote; do git branch --track '${remote hash origin/}' '$remote\'; done && git fetch --all && git pull --all #" # all branches from remote https://gist.github.com/grimzy/a1d3aae40412634df29cf86bb74a6f72
plar = !"git pull --all ${1:-origin} `git bn` #" # all branches from all remotes
plr = !"git branch $1 && git checkout $1 && git pl #" # pull de branch que nao existe localmente
plrn = !"git checkout -b $2 origin/$1 && git pl #" # igual a plr, mas escolhe nome local
plt = pull -X theirs
#pltr = pull -s recursive -X theirs <remoterepo or other repo>
ps = !"git push -u ${1:-origin} $(git bn) #"
psf = !"git push --force-with-lease ${1:-origin} $(git bn) #"
pst = !"git push --tags ${1:-origin} #"
pstd = !"git push --delete ${2:-origin} $1 #" <tagname>
psu = !"git push -u $(git rupw $1 $2) $(git bn) #" # push com user e pw
psa = !"git push -u ${1:-origin} --all && git push --tags ${1:-origin} #" # = push everything
# branches
bn = symbolic-ref --short HEAD
bo = !"git merge-base ${1:-develop} $(git bn)" # <ancestor branch> # get branch origin point
bn2 = rev-parse --abbrev-ref HEAD #produces the literal string HEAD, which is not a branch name, when you are not on a branch at all (eg detached HEAD)
brn = !git branch -m # <${se em outro branch $(git bn)}> <new-name>
bl = branch # list branches
nbr2 = branch # <newbranchname>
rbr = ls-remote # list remote branches
ab = branch -avv # list all branches
br = checkout # <branchname>
co = checkout # <branchname>
nbr = checkout -b # <newbranchname>
dev = checkout develop
m = checkout master
bc = !"git log --oneline --decorate $1..$2 #" # <branch1> <branch2> # compare
contains = branch --contains # <sha>
# dif = !"git range-diff $1..$2 #" # <branch1> <branch2> # compare
brd = branch -d # <branchname>
brd2 = !"git brd $1 && git brdr $1 ${2:-origin} #"
brdr = !"git push -d ${2:-origin} $1 #" # remote branch delete
#history:
# v2.8.0 >= git push -d origin $1
# v1.7.0 >= git push origin --delete $1
# v1.7.0 <= git push origin :$1
bz = checkout -b $1 $2 # <branch> <last-commit-of-branch> # restore deleted branch
bp = !"echo WRONG git merge-base master $(git bn)" # find branch parent of current branch
# apply commits
## single - applies like a patch
c-p = cherry-pick # <ref>
cp = cherry-pick # <ref>
cpn = cherry-pick -n # <ref> # no commit (stage only)
cpf = cherry-pick --ff # <ref> # fast forward
cpt = cherry-pick -Xtheirs # <ref> # 'theirs' strategy
cpc = cherry-pick --continue
cps = cherry-pick --skip
cpa = cherry-pick --abort
cpq = cherry-pick --quit
## merge
mt = !"f(){ git merge --no-commit --no-ff \"$1\"; git merge --abort; echo 'Merge aborted'; };f "
conflicts = diff --check
mf = merge --ff-only --no-edit # default is --ff
m- = !"git merge --no-ff $1 #" # <what> <message>
mm = !"git merge --no-ff -m '$2' $1 #" # <what> <message>
mme = !"git merge --no-ff -e $1 #" # <what> # força editar no editor
mp = !"git push . HEAD:$1 #" # <branch> # merge sem checkout (apenas ff)
ms = !"git merge --squash $1 && git commit -m ${2:-$1} #"
mc = merge --continue
ma = merge --abort
mb = branch --merged
mtf = checkout --theirs # <path/to/file>
## rebase
rb = rebase --rebase-merges
rbo = rebase --onto
rc = rebase --continue
rab = rebase --abort
ri = o # rebase interactive
rir = or # rebase interactive from root
rib = ob # rebase whole branch
# ignore
ignore = !"echo $1 >> .gitignore #"
forget = update-index --assume-unchanged # <file-case-sensitive-full-path>
unforget = update-index --no-assume-unchanged # <file-case-sensitive-full-path>
assumed = !"git ls-files -v | grep ^h | cut -c 3-" # Show the files that are currently assume-unchanged
untrack = rm -rf --cached # <folder>
# tags
t = tag # <name> <<commit>> (optional)
tg = !"git tag -a $1 -m $2 #"
to = !"git tag $2 $1 #" # <commit> <name> tag old commit, with inverted order to match git log
tom = !"git tag -a $2 -m $3 $1 #" # <commit> <name> <msg> tag old commit, with inverted order to match git log
tc = rev-list -1 # <tag> para qual commit aponta a tag
tl = tag --list
tlm = tag -ln # <tag> displays tagname/list + commit message
tlv = log --oneline --tags --no-walk # list with commit sha and msg
# tlb = !"for tag in $(git tl); do $(git branch --contains $tag) | awk -v tag=$tag '/master/{ok=NR} END {if (ok) {print tag\": yes\"} else {print tag\": NO\"}}'; done #"
tlb = !"br=${1:-$(git bn)}; \
for tag in $(git tl | sort -V); \
do out=\"${tag}: \" && git branch --contains $tag | grep $br > /dev/null && echo \"${out}yes\" || echo \"${out}NO\"; \
done #" # see which tags are in the current branch
tlbm = tlb master # see which tags are in the branch master
tr = !"git tag $2 $1 && git td $1 #"
td = tag -d # <name>
# ver pstd
tt = cat-file -t # <tag> tag type
tv = show # <tag>
# history
ref = !git reflog --no-abbrev
# lc = !"git rev-list --all --date=short --pretty=format:\"%Cred%D%x0a%Cblue%ad%x20(%ar)%x09%C(yellow)%h%x09%Creset%s\" -n ${1:-1} #" # <n> last commits, any branch
lc = !"git log --all --date=short --pretty=format:\"branch: %Cred%D%x0a%Cblue%ad%x20(%ar)%x09%Creset%an%x0a%C(yellow)%h%x09%Creset%s\" -n 1 #" # <n> last commits, any branch
# ll = !"f() { git log --oneline $* | head -3; }; f" # last logs
ll = !"git log --oneline -n ${1:-3} #" # last logs
# l = !"f() { git log --oneline $* | head -23; }; f"
l = !"git log --oneline -n ${1:-23} #"
# lf = !"f() { git log --oneline --name-status $* | head -37; }; f" # with files
lf = !"git log --oneline --name-status -n ${1:-37} #" # with files
# lg = !"f() { git log --oneline --no-abbrev --decorate $* | head -23; }; f"
lg = log --date=short --pretty=format:"%Cblue%ad%x20(%ar)%x09%C(yellow)%h%x09%Creset%s"
lga = log --date=short --pretty=format:"%Cblue%ad%x20%C(yellow)%h%x20%Creset%s" --graph --all # --oneline --decorate
msg = show -s --format=%s # <ref> display commit message
fmsg = show -s --format=%B # <ref> display full commit message
qntd = !git diff --stat ${1:-HEAD^1}..HEAD
lq = !git log --pretty=tformat:"%H" --shortstat | sed 'N;N;y/\n/ /' # one-line stats
la = log -p
g = log --all --color --graph --abbrev-commit --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset"
llt = !"git log -L '/$2/:$1' #" # <filename> <text> = line history (pode ser texto parcial)
lln = !"git log -L$2,+${3:-1}:$1 #" # <filename> <line_number> <how_many> = line number history
#lf = # file history
#git whatchanged --since= --until=
lm = !git log --oneline --all --grep="$1" # acha commits com msg
lb = !git lg --first-parent $1 # apenas commits de um branch especifico
lbn = log --pretty=format:"%D" --all
# compare
d = !git difftool HEAD~1 HEAD # shortcut: HEAD{,^}
df = !git difftool --no-prompt ${1:-HEAD}~1 ${1:-HEAD} # <refPrev> <refNext> default pega dif do commit com seu anterior. as vezes tem que usar <refPrev>..<refNext>
dn = !git diff --name-only ${1:-HEAD}~1 ${2:-HEAD}
dfa = !"f() { git diff --name-only ${1:-HEAD}~1 ${2:-HEAD} | while read filename; do git difftool "$1" --no-prompt "$filename" & done }; f #" # inclui todos commits in between pois compara o estado dos arquivos. NAO PEGA alterações que foram desfeitas
dr = !code -n $(git root)
dff = !code --diff $1 $2 #files
dfd = !code -n --wait --no-prompt --dir-diff # <refPrev> <refNext>
dft = !"f() { echo $1 > a.txt; echo $2 > b.txt; code --wait --diff --no-prompt a.txt b.txt; rm a.txt; rm b.txt; }; f" # "diff this"
bc = !"git lg $1..$2" # <branch1> <branch2> = compare
#git diff @{YYYY-MM-DD}..@{YYYY-MM-DD}
dc = diff --cached # entre ultimo commit e staged
dtf = !git diff ${1:-HEAD}~1 ${2:-HEAD} >> "$(git msg ${1:-HEAD}~1) VS $(git msg ${2:-HEAD}).diff" # to file
# lfs (now and after)
# git lfs install
lt = lfs track $1 # <ext> = "*.ext"
la = !"git add .gitattributes && git cm 'Tracking gitattributes' "
lu = lfs migrate info # unpushed
le = lfs migrate info --everything # all branches and history
lie = lfs migrate import --include=$1 # <ext> = "*.ext1,*.ext2" # by ext
lis = lfs migrate import --everything --above=$1 # <size> = 100Mb # by size
lp = push --force
lrc = reflog expire --expire-unreachable=now --all
lgc = gc --prune=now
# bfg (past commits)
# --no-blob-protection
bfs = !"java -jar %bfg%bfg.jar --strip-blobs-bigger-than $2 $1 #" # <repoFolder> <size>
bff = !"java -jar %bfg%bfg.jar --delete-files $2 $1 #" <repoFolder> <files>
bfd = !"java -jar %bfg%bfg.jar --delete-folders $2 $1 #" <repoFolder> <folder>
bfc = !"git reflog expire --expire=now --all && git gc --prune=now --aggressive"
# outros
ls = ls-tree --full-tree -r --name-only HEAD # tambem pode verificar se arquivo existe no repositorio (cuidado, case sensitive!)
zip = ls-tree --full-tree -r --name-only HEAD | 7za a bckp%date:~0,2%-%date:~3,2%-%date:~6,4%.zip Criar variavel ambiente ZIPPER e criar alias!
name = check-ref-format --normalize # <name>
valid = !"$(git check-ref-format --normalize $1) || { echo "not valid" >&2 ; exit 1 ; } #"
sha = rev-parse # <ref>
bd = !git bundle create "${1:-repo}.bundle" --all
tar = !git archive -o $(git rev-parse HEAD) --format=tar.gz -9 HEAD
rp = gc # garbages-collect repo. Repacks it
[alias] # boilerplates with patch-clone
pc = !"git merge --squash --allow-unrelated-histories $1 && echo git ac \"Patch-cloned: $1\""
pcgh = !"git fetch https://github.com/bernardoadc/$1 master:$1 && git pc $1" # Github
pcl = !"git fetch U:/Code/Boilerplates/$1 master:$1 && git pc $1" # local
[alias]
hkar = !heroku git:remote -a # <appname>
hkps = push heroku master
hklw = !heroku local web # test locally
@echo off
for /F "skip=2" %%f in ('dir /b *.gitalias') do git config --global include.path "%cd%\%%f"
git config --global include.path "%cd%\.gitalias"
echo Done
for f in *.gitalias; do git config --global include.path "$PWD/$f"; done
git config --global include.path "$PWD/.gitalias"
echo Done
[alias]
# rever..
echo = !"echo $1 #"
cloc = !"cloc --vcs=git"
cloc2 = !cloc --vcs=gitb cloc = !"cloc --vcs=git"
bs = bisect # <refPrev> <refNext>
# avaliar
logs = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
merge-span = !f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f # Given a merge commit, find the span of commits that exist(ed) on that branch. Again, not so useful in itself, but used by other aliases.
merge-log = !"git log `git merge-span .. $1`" # Find the commits that were introduced by a merge
merge-diff = !"git diff `git merge-span ... $1`" # Show the changes that were introduced by a merge
merge-difftool = !"git difftool `git merge-span ... $1`" # As above, but in your difftool
o2 = !"GIT_SEQUENCE_EDITOR=\"sed -i -n 'h;1n;2p;g;p'\" git rebase -i HEAD~2"
##trello checklist
# habilitar e salvar autenticaçao: git config credential.helper "cache --timeout 40000" (40000~=1 mes) BUGaDO. versao windows: git config --global credential.helper wincred
# when merging a feature, so you wont lose her history!: git checkout destiny && git merge --no-ff feature (no fast-forward, pq nao iria gerar um novo merge commit e só realocar os commits da feature)
# tipos/options de diff: ignore-space-at-eol, (-b) ignore-space-change, (-w) ignore-all-space, histogram, patience (nao mostra mudanças pequenas)
# git diff HEAD~1 --patience -w -b --ignore-blank-lines
# npm postinstall: git config --global alias.repl "!gitrepl"
# git config --global core.editor "code --wait"
# ls = ls-tree --full-tree -r --name-only HEAD
# zip = ls-tree --full-tree -r --name-only HEAD | 7za a bckp%date:~0,2%-%date:~3,2%-%date:~6,4%.zip Criar variavel ambiente ZIPPER e criar alias!
# name = git check-ref-format --normalize #":name"
# sha = git rev-parse #:ref
# z = reset
# zz = reset ORIG_HEAD # undo the undo
# bs = bisect #:refPrev :refNext
# \# Given a merge commit, find the span of commits that exist(ed) on that branch. Again, not so useful in itself, but used by other aliases
# merge-span = "!f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f"
# \# Find the commits that were introduced by a merge
# merge-log = "!git log `git merge-span .. $1`"
# \# Show the changes that were introduced by a merge
# merge-diff = "!git diff `git merge-span ... $1`"
# \# As above, but in your difftool
# merge-difftool = "!git difftool `git merge-span ... $1`"
git describe --tags <sha>
(da o nome)

DICAS

  • Modos: A Plain) comandos git sem 'git' B Exec) comandos bash com ! ou "!" ou !"" (multiline com "", encadeando com "&&") C Script) comandos dinamicos com !"f() { COMANDOS; }; f" (f pode ser qquer nome; multiline nao precisa "")

  • quando envolver entre !" ..." (modo B only), "... #" ou " && :" no final invalida o resto (fica como comment! e location tag) (modo C naturalmente faz isso)

  • head e tail cortam do output

  • se tiver 2 alias iguais, vai funcionar só o ultimo

  • params: $n (ex: $1) ou $* (todos)

  • parametros opcionais: ${param:-ORVALUE}, ${2:-$1} (exige ao menos modo B)

  • ?? when you use an alias like !sh -c 'git checkout -b "$1"' you should need an ending dash -: !sh -c 'git checkout -b "$1"' -

  • Usar valor dentro de outra expressao: $(expressao) ou expressao

  • string comparison: [ $1 == "" ] (espaços são mto importantes!)

  • number comparison: [ $1 -eq 5 ] (espaços são mto importantes!)

  • ternary: $([ $1 == "" ] && echo "true" || echo "false")

  • double ternary: $([ $1 == "" ] &amp;&amp; echo "true" || $([ $1 == "" ] && echo "true" || echo "false"))

  • Bash string manipulation cheatsheet: https://gist.github.com/magnetikonline/90d6fe30fc247ef110a1

  • multiline commands: !"f() {
    echo 'faz tal';
    ...
    }; f"

  • shell colors sss = !"f() {
    CY = "\033[1;33m";
    echo -e "${CY}Fetching ";
    echo;
    echo opa;
    }; f"

[alias]
zkflow = !"echo working"
# Summary
wf = nbr develop
wfi = setup
wfs = sprint
wfc = codar
wff = feat
wfy = feat
wfe = finish
wfd = done
wfr = release
# vs Gitflow
# gitflow release start = setup
# gitflow feature start = feat
# gitflow feature finish = done
# gitflow release finish = release
# Utils
v = !"f() { \
cat package.json | \
grep version | \
head -1 | \
awk -F: '{ print $2 }' | \
sed 's/[\",]//g' | \
tr -d '[[:space:]]'; \
}; f"
bump = !"ver=$(npm --no-git-tag-version version $([ $1 == "-" ] && echo "minor" || ([ $1 == "+" ] && echo "major" || echo "patch"))) && \
echo \"* **[${ver}](../../releases/tag/${ver})** - (fill)\" >> changelog.md #" #<-=minor|+=major|p=patch>
b = bump
# Flows
setup = !"git br develop && npm version minor -m 'v%s' #"
sprint = !"git nbr sprint/$1 #" # <branch-name>
codar = feat
feat = !"git nbr feature/$1 #" # <branch-name> # fatal: Cannot update paths and switch to branch 'concluir-os' at the same time.
sybr = !"f() { \
with=$1; \
br=$(git bn); \
echo Fetching ${with}; \
git br ${with}; echo; \
git pl && \
echo; \
echo Syncing with ${br}; \
git br ${br}; echo; \
git ms ${with} \"Sync with ${with}\"; \
}; f" # sync with (untouched) branch
finish = done
done = !"br=$(git bn) && \
git dev && \
git ms ${br} && \
git brd ${br} && \
git ps #" # <branch-name> # seria legal pegar do branch que estava no inicio
release = !"git ps && \
git m && \
git ms develop v$(git v) && \
git t v$(git v) && \
git ps && \
git pst && \
git dev #" # <version> # = gitflow release finish # pegar do package.json seria demais ne?
pub = !"git ps && \
git pst && \
npm publish"
#hotfix = !"git br master && \
# git nbr hotfix/$1"
# outra feature - tree de branches
# env.git?
# Qndo da um finish, sobe um nivel, faz merge, push, del the child, etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment