Information Technology Reference
In-Depth Information
origin/doc
origin/info
origin/master
Therefore, we know that the original repository contains three branches named
doc
,
info
, and
master
. The first alias,
$ git list-remote-branches
, converts
the above output in a following way:
• First it removes the item that contains
->
characters (this item informs
us that in the original repository
HEAD
contains the symbolic reference to
origin/master
).
• Then, it deletes the prefixes
origin/
.
Both operations are performed by the stream editor
sed
. The following shell com-
mand:
$ git branch -r | sed "/->/d"
removes the line that contains
->
. The syntax to filter out some lines with
sed
is:
$ sed "/PATTERN/d"
The above command filters out all the lines that contain the
PATTERN
.
To remove prefix
origin/
we use
sed's
substitution command—its syntax is
the following:
$ sed "s/PATTERN/REPLACEMENT/"
where
PATTERN
defines the strings that will be replaced,
REPLACEMENT
is a new
string, slashes are used as separators, and
s
stands for substitute.
The command:
$ git branch -r | sed "s/ origin\///g"
replaces all occurrences of
origin/
with an empty string. Because our
PATTERN
contains a slash we have to escape it with
\
.
When we combine both
sed
commands using a semicolon as a separator into one
processing instruction: