Reputation: 225
I have two svn remote branches after migration now how to changes all the remote branch to git local branches using below sed command
$ git branch -r
svn-origin/branch-A
svn-origin/branch-B
Here how to remove svn-origin/
to git local branch.
$ git branch -r | grep branch | sed 's/svn-origin//'
My required output is something like this:
$ git branch
branch-A
branch-B
Upvotes: 0
Views: 1318
Reputation: 476699
You can simply use different separation markers, for instance #
:
git branch -r | grep branch | sed 's#svn-origin/##'
Now sed
will replace svn-origin/
with the empty string. sed
reads the s
command, and the next character it considers to be the separator. So in case you want to use /
(or any other character in your expressions), simply use a different separator.
If you want to remove the leading spaces as well, you can use:
git branch -r | grep branch | sed 's#^\s*svn-origin/##'
So with \s*
to remove the spaces and ^
as anchor point (^
is not required).
Upvotes: 1
Reputation: 18381
git branch -r |awk -F'/' '/branch/{print $NF}'
OR
git branch -r |grep branch|sed -r 's|(^.*/)(.*)|\2|'
Upvotes: 1