title: How to write a shell script that checks if git repository is up to date?
body: <pre><code>#!/bin/bash
  #gedit tidy plugin
  init=false
  SRC_DIR=~/repos
  
  DIRECTORY="Gedit-Clientside-Plugin"
  #making repos directory
  if [ ! -d "$SRC_DIR" ]; then mkdir $SRC_DIR; fi
  
  
  
  if [ ! -d "$SRC_DIR/$DIRECTORY" ]; then
      init=true
      cd $SRC_DIR &amp;&amp; pwd &amp;&amp; git clone git://github.com/trentrichardson/Gedit-Clientside-Plugin.git &amp;&amp; cd $DIRECTORY
  else
      cd $SRC_DIR/$DIRECTORY
  fi
  #below here is what I'm having trouble with
  git pull 1&gt;&amp;1 | grep "Already up-to-date."
  
  if [[ ! $? -eq 0 &amp;&amp; ! $init ]]; then
      read -e -p "## Branch moved, build and install Gedit-Clientside-Plugin? [Y/n] " yn
      if [[ $yn == "y" || $yn == "Y" || $yn == "" ]] ; then
          if [ ! -d "/usr/share/gedit/plugins/clientside" ]; then
              sudo cp ~/repos/Gedit-Clientside-Plugin/clientside /usr/share/gedit/plugins/ -r
          else
              echo "Directory already exists."
          fi
      fi
  fi
  </code></pre>
  
  <p>The above code is something I have edited from a script I have found on stackoverflow to install Emacs from git repository. What I want this script to do is to install any programs from git repos, and update them if an update is necessary. Of course I will have to provide the steps to install it. In this script's case it just needs to copy the <code>clientside</code> directory to <code>/usr/share/gedit/plugins/</code> directory.</p>
  
  <p>I do not need any help with how to install any script but what I need is how to check if repository is up to date and go from there.</p>
  
  <p>Right now what I don't understand is this part:</p>
  
  <pre><code>git pull 1&gt;&amp;1 | grep "Already up-to-date."
  
      if [[ ! $? -eq 0 &amp;&amp; ! $init ]]; then
  .....
      fi
  </code></pre>
  
  <p>When I run <code>git pull 1&gt;&amp;1 | grep "Already up-to-date." &amp;&amp; $?</code> in terminal the output is <code>Already up-to-date. 0</code>. So I understand that this is the part that checks for updates however the next part doesn't execute (the if statement)- which is the part that copies the directory to gedit plugin directory. I do not understand what <code>1&gt;$1</code> means or what <code>$?</code> means. Therefore I could not solve the problem... And what I do not understand is why it thinks that <code>Branch is moved</code> when it is not up to date (I'm just assuming that it says that when <code>git pull</code> doesn't return <code>0</code> in the if statement).</p>
  
  <p>I'm sure it has a simple solution and the answer will be both educating for bash and git. I appreciate all the help.</p>
  
  <p>I'm using ubuntu 12.04.</p>