Created
April 11, 2017 20:26
-
-
Save supercoffee/122d1540e7bf5a3088cb8d6ea90eea84 to your computer and use it in GitHub Desktop.
Prevent push to Upstream Git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edit the
DISALLOWED_PUSH
variable to prevent pushes to any repo(s) that you want.Installation
.git/hooks/
directorypre-push
:mv pre-push.py pre-push
chmod +x pre-push