2

I'm trying to extract the name of the folder created by git. The output says:

...
Cloning into 'repository-name'...
...

I want to pipe this output into grep to extract the one line that says Cloning into 'repository-name'. However, when I run git clone https://github.com/username/repository-name.git | grep "Cloning into", git appears to bypass grep and print output directly to the screen, since I get the full git output message with no grep highlighting. Sending the --no-pager flag to git doesn't help.

1 Answer 1

3

From git-clone man page:

--progress
Progress status is reported on the standard error stream by default when it is attached to a terminal, unless --quiet is specified. This flag forces progress status even if the standard error stream is not directed to a terminal.

So we have to do Redirecting of Standard Descriptors as git-clone outputs on the standard error stream.

This will probably do

git clone https://github.com/username/repository-name.git --progress 2>&1 | grep "Cloning into"

3
  • That's a bit weird that they would print to stderr even when there are no errors... But thanks @Aaryan for the solution.
    – LorenDB
    Commented Jul 3, 2020 at 21:55
  • Yeah, I was surprised too, but probably they had a reason for this, maybe some extensive search on the net will give us some discussion forum ( just guessing ). Commented Jul 4, 2020 at 8:46
  • 1
    This mailing list thread has a take on the issue.
    – LorenDB
    Commented Jul 4, 2020 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .