1

I'm trying to save the output of git clone into a bash variable. When I do the below, I only get the first line

DIR=$(git clone repo_url  >& /dev/stdout)
echo $DIR

Output:

Cloning into [repo_name]...

How can I save the entire output of git clone?

I've tried this on Ubuntu and MacOS.

Desired output

remote: Enumerating objects: 57, done.
remote: Counting objects: 100% (57/57), done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 9163 (delta 28), reused 30 (delta 11), pack-reused 9106
Receiving objects: 100% (9163/9163), 14.62 MiB | 44.41 MiB/s, done.
Resolving deltas: 100% (7014/7014), done.
Harry M
  • 1,848
  • 3
  • 21
  • 37

1 Answers1

2

Try using --progress fr the full output.

DIR=$(git clone --progress repo_url  >& /dev/stdout)

>& redirects both stdout and stderr, which is correct considering git commands often outputs information on stderr.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250