``with pushd(repo_dir)`` is a helper you can use. Example: https://github.com/kumar303/ezboot/blob/master/ezboot/__init__.py#L297