Skip to content

Instantly share code, notes, and snippets.

@GMNGeoffrey
Last active August 18, 2021 17:20
Show Gist options
  • Save GMNGeoffrey/a1a2cc1baf811ce4ebcdeab6c24e8a2d to your computer and use it in GitHub Desktop.
Save GMNGeoffrey/a1a2cc1baf811ce4ebcdeab6c24e8a2d to your computer and use it in GitHub Desktop.
git-sudo
#!/bin/bash
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
# Protect yourself from accidentally pushing upstream. Leave the
# upstream push URL as a fake DISABLE. Then temporarily enable pushes
# when you do need them with this custom git subcommand. Run:
# `git sudo [command]` to run the `command` but with pushing to
# upstream enabled, e.g. `git sudo push upstream main`
git remote set-url --delete --push upstream DISABLE
git "$@"
git remote set-url upstream --push DISABLE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment