title: How to use python to check for the latest git branch?
body: <p>My goal:
  My project should periodically check in with my GitHub repo to see if it is currently up to date with the master branch.</p>
  
  <p>What I've tried to do is to use this bash code (<a href="https://stackoverflow.com/a/3278427/10653826">https://stackoverflow.com/a/3278427/10653826</a>) and implement into Python, seeing as my project is in Python. 
  Since I only want to see if LOCAL != REMOTE (at which point it sends a notification message that it's not up to date any more), I'm using the following code:</p>
  
  <pre class="lang-py prettyprint-override"><code>LOCAL=subprocess.check_output(['git', 'rev-parse', '@'], stdin=None, stderr=None, shell=False, universal_newlines=False)
  REMOTE=subprocess.check_output(['git', 'rev-parse', '@{u}'], stdin=None, stderr=None, shell=False, universal_newlines=False)
  
  if (LOCAL != REMOTE) :
      #does stuff here.
  </code></pre>
  
  <p>I'm sure it would be a lot better to write this in python instead of using subprocess to complete it in bash. But my goal is to get it to work first at least, then worry about that stuff.</p>
  
  <p>So my problem is...
  This works fine when I call it locally: <code>sudo python3 ./script.py</code>
  But when I set it up in a <code>crontab -e</code> then I get errors.</p>
  
  <pre><code>fatal: not a git repository (or any of the parent directories): .git
  Traceback (most recent call last):
    File "/github/Scraper-Discord-Notification/main.py", line 24, in &lt;module&gt;
      discord_client = DiscordClient(discord_config)
    File "/github/Scraper-Discord-Notification/kijiji_scraper/discord_client.py", line 24, in __init__
      self.check_version(update_notification_count)
    File "/github/Scraper-Discord-Notification/kijiji_scraper/discord_client.py", line 85, in check_version
      LOCAL=subprocess.check_output(['git', 'rev-parse', '@'], stdin=None, stderr=None, shell=False, universal_newlines=False)
    File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
      **kwargs).stdout
    File "/usr/lib/python3.6/subprocess.py", line 438, in run
      output=stdout, stderr=stderr)
  subprocess.CalledProcessError: Command '['git', 'rev-parse', '@']' returned non-zero exit status 128.
  fatal: not a git repository (or any of the parent directories): .git
  Traceback (most recent call last):
    File "/github/Scraper-Discord-Notification/main.py", line 24, in &lt;module&gt;
      discord_client = DiscordClient(discord_config)
    File "/github/Scraper-Discord-Notification/kijiji_scraper/discord_client.py", line 24, in __init__
      self.check_version(update_notification_count)
    File "/github/Scraper-Discord-Notification/kijiji_scraper/discord_client.py", line 85, in check_version
      LOCAL=subprocess.check_output(['git', 'rev-parse', '@'], stdin=None, stderr=None, shell=False, universal_newlines=False)
    File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
      **kwargs).stdout
    File "/usr/lib/python3.6/subprocess.py", line 438, in run
      output=stdout, stderr=stderr)
  subprocess.CalledProcessError: Command '['git', 'rev-parse', '@']' returned non-zero exit status 128.
  fatal: not a git repository (or any of the parent directories): .git
  Traceback (most recent call last):
    File "/github/Scraper-Discord-Notification/main.py", line 24, in &lt;module&gt;
      discord_client = DiscordClient(discord_config)
    File "/github/Scraper-Discord-Notification/kijiji_scraper/discord_client.py", line 24, in __init__
      self.check_version(update_notification_count)
    File "/github/Scraper-Discord-Notification/kijiji_scraper/discord_client.py", line 85, in check_version
      LOCAL=subprocess.check_output(['git', 'rev-parse', '@'], stdin=None, stderr=None, shell=False, universal_newlines=False)
    File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
      **kwargs).stdout
    File "/usr/lib/python3.6/subprocess.py", line 438, in run
      output=stdout, stderr=stderr)
  subprocess.CalledProcessError: Command '['git', 'rev-parse', '@']' returned non-zero exit status 128.
  </code></pre>
  
  <p>Now, my understanding of this error is that it's not being called in a directory which contains the .git.
  I've tried doing a number of different things, including 
  <code>subprocess.call(['cd', '/path/to/the/.git'])</code>
  which replies with an error that looks similar to this:
  <code>FileNotFoundError: [Errno 2] No such file or directory: 'cd ': 'cd '</code></p>
  
  <p>I've tried different variations on this method, and I don't seem to be having any luck.</p>