Escaping shell command in git alias -


i have command deletes local branches not in repo anymore, i'm trying add in .gitconfig:

git checkout master && git fetch -p && git branch -l | sed 's/* master//' > /tmp/gitlocal.txt && git branch -r | sed 's/origin\///' > /tmp/gitremote.txt && grep -fxv -f /tmp/gitremote.txt /tmp/gitlocal.txt | xargs git branch -d 

i'm trying put alias, i'm getting escaping problems

cleanbranches = "!f() { git checkout master && git fetch -p && git branch -l | sed 's/* master//' > /tmp/gitlocal.txt && git branch -r | sed 's/origin\///' > /tmp/gitremote.txt && grep -fxv -f /tmp/gitremote.txt /tmp/gitlocal.txt | xargs git branch -d; }; f" 

after trial , error, i've concluded

sed 's/origin\///' 

is making alias break. if remove part, commands executed (but it's deleting every branch, instead of keeping 1 still on repo), , have no errors

any on how can escape ?

extra, not necessary, if explain part of alias doing , why there 3 slashes?

you can rewrite sed 's/origin\///' using different separator, example, sed 's|origin/||' (this command removes substring origin/ input).

so alias can set using:

git config --global alias.cleanbranches '!git checkout master && git fetch -p && git branch -l | sed "s/* master//" > /tmp/gitlocal.txt && git branch -r | sed "s|origin/||" > /tmp/gitremote.txt && grep -fxv -f /tmp/gitremote.txt /tmp/gitlocal.txt | xargs git branch -d' 

i don't recommend editing .gitconfig directly, because it's hard escaping right. removed function wrapper (f() { ...; }; f), because don't think it's required.

i not recommend using git branch -d in such automated way (i did not review commands inside alias, can't tell whether safe).


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -