Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: unable to redirect/parse the output of 'git fetch --dry-run' command

What is special about the output message of git fetch command that is printed on the console? I'm not able to use grep, xargs, etc. Not able to redirect the output to a file also..

Note: I'm using git fetch --dry-run command

[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ git fetch --dry-run > /tmp/1
From ssh://git.code.sf.net/p/santest/code
   9f068d0..2b9dc4e  master     -> origin/master
[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ cat /tmp/1              <= no data
[sangeeth@localhost santest-code]$  
[sangeeth@localhost santest-code]$ git fetch --dry-run | grep "ssh"     <= output has both lines
From ssh://git.code.sf.net/p/santest/code
   9f068d0..2b9dc4e  master     -> origin/master
[sangeeth@localhost santest-code]$ 
[sangeeth@localhost santest-code]$ git --version 
git version 1.7.11.4
[sangeeth@localhost santest-code]$ 

I'm trying to parse the output of git fetch --dry-run command to check whether the local (master) branch is up-to-date with the remote (origin/master) branch.

like image 572
Sangeeth Saravanaraj Avatar asked Oct 30 '12 19:10

Sangeeth Saravanaraj


1 Answers

Some of git's status output goes to STDERR. If you want to grep through it, merge STDERR into STDOUT like so:

git fetch --dry-run 2>&1 | grep ssh
like image 193
Dan Fitch Avatar answered Oct 06 '22 02:10

Dan Fitch