title: Bash/Shell Script Function to Verify Git Tag or Commit Exists and Has Been Pushed to Remote Repository
body: <p>I wanted to get this question out there to see if I'm doing this right.  The following script works <strong>except for checking to see if the commit has been pushed to a remote repo</strong> which I can't find the right command for:</p>
  
  <pre><code>#!/bin/bash
  set -e  # fail on first error    
  verify_git_ref() {
          log "Verifying git tag or commit: \"$1\" ...."
          if git show-ref --tags --quiet --verify -- "refs/tags/$1"
          then
              log_success "Git tag \"$1\" verified...."
              GIT_TAG_OR_REF=$1
              return 0
          elif git rev-list $1&gt;/dev/null 2&gt;&amp;1
          then
              log_success "Git commit \"$1\" verified...."
              GIT_TAG_OR_REF=$1
              return 0
          else
              log_error "\"$1\" is not a valid tag or commit, you must use a valid tag or commit in order for this script to continue"
              return 1
          fi
      }
  </code></pre>
  
  <p>Related:
  <a href="https://stackoverflow.com/questions/3080509/git-list-commits-not-pushed-to-the-origin-yet">List Git commits not pushed to the origin yet</a></p>