Zip184 Zip184 - 1 month ago 7
Git Question

Using substring with xargs in cygwin

I'm trying to use substring functionality with on the

portion of an xargs piped statement in cygwin. Here's my command without the substring:

git branch -r --merged master | grep "feature/" | xargs -I {} git push origin :{}

This is almost what I need it to do, but the command string generated by the first two parts has a "origin/" in front of it. So I just need to cut this off. I read about using
for substring. This is how I'm trying to use it:

git branch -r --merged master | grep "feature/" | xargs -I {} git push origin :${{}:7}

but I'm getting the "bad substitution" error message because it looks like that command needs a variable and doesn't like the
. I know I could probably get around this by writing a simple bash script to iterate over the list generated by
git branch -r --merged master | grep "feature/"
but I'm guessing there's some small syntax I could change to get this working.


{} is not a shell variable. You can pass it to bash -c command line:

git branch -r --merged master | grep "feature/" | 
xargs -I {} bash -c 'git push origin ":${1#origin/}"' - {}

${1#origin/}" will remove origin/ at the start of $1.