Skip to content

Instantly share code, notes, and snippets.

@kadnan
Created May 15, 2017 10:22
Show Gist options
  • Select an option

  • Save kadnan/0d97ce7e7df0ceef789609f7513fc220 to your computer and use it in GitHub Desktop.

Select an option

Save kadnan/0d97ce7e7df0ceef789609f7513fc220 to your computer and use it in GitHub Desktop.
Gist for Automating remote and local git commands
from fabric.api import *
from fabric.colors import red, green
from time import sleep
from pprint import pprint
from fabric.contrib.files import exists
def local_git():
is_done = True
try:
with lcd('/Development/PetProjects/OhBugz/src/ohbugztracker/'):
r = local('git status', capture=True)
# Make the branch is not Upto date before doing further operations
if 'Your branch is up-to-date with' not in r.stdout:
local('git add .', capture=True)
local('git commit -m Initial Commit')
local('git push origin master')
except Exception as e:
print(str(e))
is_done = False
finally:
return is_done
def remote_git():
is_done = True
try:
with settings(host_string=host.rstrip('\n').strip(), warn_only=True):
with cd('public_html/code'):
run('git stash')
run('git pull origin master')
except Exception as e:
print(str(e))
is_done = True
finally:
return is_done
def deploy():
result = local_git()
if result:
print('Time to deploy')
@Pehesi97
Copy link
Copy Markdown

Hey, where does the "host" var come from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment