Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from serverfault.com Dec 18 '16 at 21:59

This question came from our site for system and network administrators.

up vote 2 down vote accepted

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

Example: git fetch -v >& test.txt

share|improve this answer
    
thanks a lot Simon didnt knew about stderr! – SipriusPT Dec 16 '16 at 9:34

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).
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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