Skip to content

Instantly share code, notes, and snippets.

@VeeeneX
Last active August 18, 2016 14:50
Show Gist options
  • Save VeeeneX/9bd72671f66c72d22bcea96ec4b6e9dc to your computer and use it in GitHub Desktop.
Save VeeeneX/9bd72671f66c72d22bcea96ec4b6e9dc to your computer and use it in GitHub Desktop.
Sh (Subprocess) vs Os
import os
# Executed with output:
# Already on 'develop'
# Your branch is up-to-date with 'origin/develop'.
os.system('git --git-dir /tmp/app/.git --no-pager checkout -f develop')
# Git status returns:
# On branch develop
# Your branch is up-to-date with 'origin/develop'.
# nothing to commit, working directory clean
from sh import git
# Steps
# 1. Clone branch to folder
# 2. Switch branch
# Executed 2 times with output:
# Already on 'develop'
# Your branch is up-to-date with 'origin/develop'.
for line in git.checkout("-f", branch, _err_to_out=True, _iter=True):
print(line)
# Git status returns:
# deleted: docker-compose-dev.yml
# modified: src/index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment