Can't using pipe within “git.exe fetch origin” under Windows batch

I wrote a batch to check and deploy the rails app from github, the batch file see below. The problem is git.exe fetch origin | find "remote: Counting Objects" always returns errorlevel 1, even when we have new commits. I must terminate the Rails App first, because some files are locked (*.jars) and cause the git pull command to fail.

I search and found below topic, but even using git.exe instead of the git.cmd, the problem still exists.

  • Run batch file with git pull in gitbash
  • Cannot run git pull command through php
  • Git command line and batch file have different output
  • Difftool for binary files in git
  • Start Tomcat on Console from Jenkins
  • Running a batch file in git shell
    • Check if pull needed in Git
    • git bash : how to check if there's a new commit available

    I try to using a temp file to store git.exe fetch origin result, but if seems this command always print the result to the console.


    git pull | find "Already up-to-date."
    if %errorlevel% == 1 (

    Works fine

        REM @echo off
        set path=%path%;C:\Program Files\Git\bin;D:\jruby-1.6.7\bin
        set JRUBY_OPTS=--1.9
        git.exe fetch origin | find "remote: Counting objects"
        if %errorlevel% == 0 taskkill /f /im:jruby.exe
        git pull | find "Already up-to-date."
        if %errorlevel% == 1 (
          start cucumber.bat
          REM do something else when update
        REM RAILS
        tasklist | find "jruby.exe"
        if %errorlevel%==1 (
         echo @rails s > rail.bat
         echo @exit >> rail.bat
         start cmd /c rail.bat

  • What should be in my .gitignore for an Android Studio project?
  • Creating a 'git log' alias with formatting
  • missing files after git merge
  • How can I return back to my previous location after I have already committed a change
  • how to use git to both protect my works and get updates?
  • Eclipse, Git and Bitbucket - Can't push - Error 401 Unauthorized
  • One Solution collect form web for “Can't using pipe within “git.exe fetch origin” under Windows batch”

    At a guess I’d say it’s breaking because the ‘Counting objects’ line shows a dynamic progress indicator, but don’t quote me on that.

    git fetch origin
    git branch -a --no-merged |find "remotes/origin"
    if %errorlevel% == 0 taskkill /f /im:jruby.exe

    You might also want to limit it to just the current branch:

    git branch -a --no-merged |find "remotes/origin/mybranch"
    Git Baby is a git and github fan, let's start git clone.