When I run git clone like usual, I see this:
$ git clone https://github.com/bensmithett/webpack-css-example
Cloning into 'webpack-css-example'...
remote: Counting objects: 179, done.
remote: Total 179 (delta 0), reused 0 (delta 0), pack-reused 179
Receiving objects: 100% (179/179), 24.07 KiB | 0 bytes/s, done.
Resolving deltas: 100% (79/79), done.
Checking connectivity... done
However, when I try to redirect that to a file (or store it in a shell variable) I only see this:
Cloning into 'webpack-css-example'...
Here is what I tried:
$ git clone https://github.com/bensmithett/webpack-css-example 2>&1 | tee out.log
$ cat out.log
Cloning into 'sample-data'...
I tried it in Node.js as well, and it does the same thing:
const fs = require('fs');
const child = spawn('git clone https://github.com/bensmithett/webpack-css-example');
child.stdout.on('data', function(data){
console.log(String(data));
});
child.stderr.on('data', function(data){
console.log(String(data));
});
// Cloning into 'webpack-css-example'...
Why is all the remote:
etc. stuff not getting piped to either stdin/stderr? Is there any way to capture the output? If not, what is happening that makes it so the output is displayed in the terminal, yet it is not being passed through either stdout or stderr?
The git clone command copies an existing Git repository. This is sort of like SVN checkout, except the “working copy” is a full-fledged Git repository—it has its own history, manages its own files, and is a completely isolated environment from the original repository.
Developers should be aware that the depth 1 clone operation only pulls down one branch. If the remote repository contains other branches, they won't be able to check them out locally without a pathspec error. After a git clone depth 1 operation, attempts to checkout an alternate branch will trigger a pathspec error.
You successfully cloned a Git repository into a specific folder on your server. In this case, you cloned the master branch from your Git remote repository. You can check the current branch cloned by running the “git branch” command.
By default Git will display the cloning progress only when the standard error stream is directed to a terminal. Since you're redirecting it to the pipe, the output stream is no longer attached to the terminal. So in order to capture the output, you need to add --progress
parameter to force the progress status, e.g.
git clone --progress https://github.com/foo/bar 2> out.log
or, in order to store the output in a shell variable
out=$(git clone --progress https://github.com/foo/bar 2>&1)
See: man git-clone
--progress
Progress status is reported on the standard error stream by default when it is attached to a terminal, unless
-q
is specified. This flag forces progress status even if the standard error stream is not directed to a terminal.
To force the terminal in any other way, you'll have to preload some library to force isatty()
to return always true (see: man isatty
). This function is used by git across the source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With