Skip to content

Instantly share code, notes, and snippets.

@supercoffee
Created April 11, 2017 20:26
Show Gist options
  • Save supercoffee/122d1540e7bf5a3088cb8d6ea90eea84 to your computer and use it in GitHub Desktop.
Save supercoffee/122d1540e7bf5a3088cb8d6ea90eea84 to your computer and use it in GitHub Desktop.
Prevent push to Upstream Git
#!/usr/bin/env python3
import argparse
DISALLOWED_PUSH = ['upstream']
def assert_safe_push(remote, branch):
if remote in DISALLOWED_PUSH:
print('Error: push to {remote} is not allowed'.format(**{'remote': remote}))
exit(1)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('remote')
parser.add_argument('branch')
args = parser.parse_args()
assert_safe_push(args.remote, args.branch)
if __name__ == '__main__':
main()
@supercoffee
Copy link
Author

Edit the DISALLOWED_PUSH variable to prevent pushes to any repo(s) that you want.

Installation

  1. Copy this into your repo's .git/hooks/ directory
  2. Rename it to pre-push: mv pre-push.py pre-push
  3. Make it executable: chmod +x pre-push

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