Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a certain command (git push server-name) that has major consequences. How to require confirmation for this command only? It should ignore white space.

The confirmation could be Enter 'yes i am sure.' to confirm:

By the way, there is another command that does not require confirmation: git push server-name-staging.

share|improve this question
You could wrap something around that resembles the answers to SO's "How do I prompt a user for confirmation in bash script?", combine it with this answer...(Not sure if you can override push, but you could create a new macro name and slightly alter your habbits.) This is guesswork, I'm unsure if it's possible to pass arguments to these aliases. – sr_ Apr 13 '12 at 17:06
That's very helpful info. I thought since it is a bash script it belongs on Unix.SE. – B Seven Apr 13 '12 at 21:12
up vote 7 down vote accepted

Alias git to a script you're going to write:

$ alias git=mygit

...which lives in your PATH somewhere and looks like this:

if [ "$1" = "push" ]
    /bin/echo -n "Enter 'yes i am sure.' to confirm: "
    read answer
    if [ "$answer" != "yes i am sure." ]
        echo So indecisive...
        exit 1

git "$@"
share|improve this answer
use "$@" instead of "$*" -- the former will protect any argument that contains whitespace. In some shells, you can read -p "Enter 'yes i am sure.' to confirm: " answer – glenn jackman Apr 13 '12 at 17:47
Yep, $* is a bad habit of mine. :) Fixed that. I'll keep the read command as-is for portability. – Warren Young Apr 13 '12 at 18:15
The outer conditional is not needed anymore with "$@". – Stéphane Gimenez Apr 13 '12 at 19:00
True. Fixed. Thanks! – Warren Young Apr 13 '12 at 19:17
Thanks. Thinking about it more, it is not really necessary to use alias git=mygit. It might be better to use a separate command for git push. A new command push that runs the above script: if ["$1" = "server-name"] .... That's actually safer because then we don't need git "$@" – B Seven Apr 13 '12 at 21:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.