I wanted to write the output of git clone
to a file using
git clone https://github.com/someRepository > git_clone.file
But instead I get the output displayed/updated in the terminal like
Cloning to 'someRepository' ...
remote: Counting objects: 2618, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 2618 (delta 2), reused 12 (delta 1), pack-reused 2603
Received objects: 100% (2618/2618), 258.95 MiB | 4.39 MiB/s, Done.
Resolving Differences auf: 100% (1058/1058), Done.
Check Connectivity ... Done.
But the file git_clone.file
is generated but remains empty.
My original goal was to bypass the output of git
into a function (see my question here). But now I realized git
doesn't even seem to produce the output to stdout
really but somehow different since nothing is written to the file.
How can I get this displayed output from git
in order to redirect it to a file/function?
EDIT
The proposed redirection of stderr
(and stdout
) did not solve the problem.
git clone https://github.com/someRepository 2> git_clone.file
git clone https://github.com/someRepository &> git_clone.file
git clone https://github.com/someRepository > git_clone.file > 2>&1
all gave me the same result: only the line
Cloning to 'someRepository' ...
appears in git_clone.file
BACKGROUND INFORMATION
Why do I need this?
As explained in my other question here I wrote a custom progress bar always at the bottom of the output my scripts. (I use it in multible scripts but) The script in this case migrates a lot of (until now 107) git repositories from github to our own Gitlab-Server and repairs the Git LFS support which usually is lost without it.
So I would like to still see all the output of git but also would like to have my progress bar working at the bottom of the output in the terminal.
Best Answer
Thanks for your help!
I just have found the solution:
Part 1
(Thanks to the answer of dessert)
git
by design does never write tostdout
butstderr
. So I needed to redirectstderr
, too, in order to get the output usingPart 2
Anyway this wasn't enough and I only received the "uninteresting" part of the output to the file but not the lines of the progress I really wanted.
Doing further reserach again in
man git-clone
I realized there exists an optionThough I'ld think it actually was already attached to a terminal, this now seems to force git to write the lines of the progress part I'm most interested in finally to
stderr
as well so I can now get them using