git - Creating remote tracking branches using bash one-liner doesn't behave the same as running the commands manually -


if run following command:

for r in $(git branch -r | grep -po "(?<=myremote/).*"); echo git branch --track $r myremote/$r; done 

i following output:

git branch --track foo myremote/foo git branch --track bar myremote/bar git branch --track baz myremote/baz 

if run these echoed commands individually, following output:

branch foo set track remote branch foo myremote. branch bar set track remote branch bar myremote. branch baz set track remote branch baz myremote. 

on other hand, if run following one-liner (simply removing "echo"):

for r in $(git branch -r | grep -po "(?<=myremote/).*"); git branch --track $r myremote/$r; done 

the branch creation fails following output:

fatal: 'foo' not valid branch name. fatal: 'bar' not valid branch name. fatal: 'baz' not valid branch name. 

why might happening, there different command that's being run? how can debug since?

update:

there appears invisible control characters flowing through unix pipe, when specify --color=never grep. if change regex (?<=myremote/)[\w]* problem solved. however, still don't understand erroneous control character coming from. if add echo $r | od -c output view raw data coming through pipe, it's clear there control characters there:

output original regex:

0000000   f   o   o 033   [   m  \n 0000007 

output new regex:

0000000   f   o   o  \n 0000004 

what character , did come since added --color=never option?

this worked fine me

git branch -r | awk '/myremote/{print $2}' fs=/ | while read q   git branch --track $q myremote/$q done 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -