You can just do `os.environ.get('CIRCLE_BRANCH') or os.environ.get('TRAVIS_BRANCH', git('rev-parse', '--abbrev-ref', 'HEAD').strip()),` (and note that the `None` is unnecessary because the second argument of `get` defaults to `None`)