Last active
November 29, 2022 19:25
-
-
Save pesterhazy/00744bbc4413c61a82fc4695f7cfc4f2 to your computer and use it in GitHub Desktop.
Yikes! A safer git push
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 bash | |
# | |
# When using "git push", I frequently find myself overlooking git's | |
# dreaded 'Updates were rejected because the remote contains work that | |
# you do not have locally' error message. | |
# | |
# After I push, I don't typically wait around for the command to | |
# complete. So while I _think_ that my changes have been pushed to | |
# remote branch, in fact the push wasn't successful. Because the | |
# branch has changed in the meantime, I need to `git pull --merge` to | |
# integrate before git allows me to push. | |
# | |
# In fact this happens so often that my colleagues are getting | |
# annoyed. Is there a way to make this more obvious? Make a sound? | |
# Show something really obvious on the screen, in case the speaker is | |
# muted? | |
# | |
# I'm glad you asked. Let me introduce you to yikes! | |
# | |
# Installation: | |
# | |
# - Calls this script `yikes`, make it executable and put in on your path | |
# - add this section to ~/.gitconfig | |
# | |
# ``` | |
# [alias] | |
# yikespush = "!git push \"$@\" || yikes" | |
# ``` | |
# | |
# - add this section to ~/.zshrc | |
# | |
# ``` | |
# function do_git { | |
# cmd="$1" | |
# if [[ "$cmd" == "push" ]]; then | |
# cmd="yikespush" | |
# fi | |
# command git "$cmd" "${@:2}" | |
# } | |
# alias git='do_git' | |
# ``` | |
# | |
# This works on macOS and zsh. If you use fish on Linux, you're out of | |
# luck. On the upside, you're probably smart enough to translate these | |
# instructions to your preferred environment. | |
set -euo pipefail | |
osascript -e 'display notification "Yikes"' | |
say yikes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment