I have tried several ways to save into a log file 'git fetch output' from terminal, through a bash file but without success, like,

git fetch origin > output.log

or even adding output.log in the front of the bash script where i have 'git fetch origin'.

With command script is the only way i have to record all the info into a txt file through '>', but i would have to insert it manually and it stops when i try to use it inside of a bash file to let me introduce commands, dont know if there is a way to use a bash file to insert 'git fetch origin' command inside of script command.

This is a sample of how the output in terminal is after i execute 'git fetch origin' command,

Xserver$ git fetch origin > output.log
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 5), reused 0 (delta 0)
Unpacking objects: 100% (14/14), done.
From https://bitbucket.org/x/test
 * [new branch]      branch1    -> origin/branch1
 * [new branch]      branch2    -> origin/branch2
 * [new branch]      branch3    -> origin/branch3
 * [new branch]      branch4    -> origin/branch4
 * [new branch]      master     -> origin/master

Is there a way to save this output to a txt file?

2 Answers 2


Looks like git prints the output to stderr, so you should use >&.

Example: git fetch -v >& test.txt


There is a command called script which can be used to save the terminal output of any command. It could for example be invoked like this:

script -f output.log -c 'git fetch origin'

Unlike ordinary redirection the command will still see stdout and stderr connected to a pts device, so commands which use different formatting for file output and terminal output will still be producing all the terminal formatting sequences.

Additional with script the output will be send to both your terminal and to the specified log file. Whether to use script or ordinary redirection depends on your exact usage scenario.

The parameters in the above command have the following meaning:

  • -f write output to the log file immediately when produced (by default output is buffered).
  • output.log the file name to write output to (by default named typescript).
  • -c 'git fetch origin' the command to invoke (by default a shell will be started).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.