Skip to content

Instantly share code, notes, and snippets.

@compumike08
Last active January 7, 2017 22:39
Show Gist options
  • Save compumike08/47901583b69a10479e10b65fb383de09 to your computer and use it in GitHub Desktop.
Save compumike08/47901583b69a10479e10b65fb383de09 to your computer and use it in GitHub Desktop.
Script to prevent accidentally running the older version of GPG which is built into Git for Windows
#!/bin/bash
# This script prevents the version of GPG that is built
# into Git BASH for Windows from being run accidentally.
# It is for the very specific situation when, on a Windows
# machine, you have a newer version of GPG installed on
# your machine directly, and you also have Git BASH for Windows.
# In this circumstance, running the 'gpg' command from a Windows
# command line prompt will invoke the newer version of GPG installed
# directly, but invoking 'gpg' from the Git BASH terminal will
# invoke the older GPG version built into Git for Windows.
# You can force Git itself to use the newer version of Git built
# into Windows by running the following command:
# git config --global gpg.program "c:/Program Files (x86)/GNU/GnuPG/gpg2.exe"
# However, while that command will cause Git to always use the newer
# GPG version, if you try to run a 'gpg' command from the Git BASH
# terminal directly, the older version of GPG will still run.
# Since the older version and the newer version store the keys
# in different locations, this can cause confusion. If you need to
# run a 'gpg' command, you must do so from a Windows command line prompt.
# To prevent you from forgetting and accidentally running a 'gpg' command
# directly from Git BASH, you can use this script to block any attempt
# to invoke a 'gpg' command directly from Git BASH, while still allowing
# you to use Git BASH to invoke Git commands which then call gpg, as well
# as allowing you to run 'gpg' commands from Windows command line prompts.
# Place this script in your "C:\Users\<username>\bin" folder
# If that folder doesn't exist, then create it.
# Once this script is in place, if you accidentially try to
# invoke a 'gpg' command directly from a Git BASH terminal, this
# script will be invoked instead and a warning message will be displayed
# reminding you to use the Windows command prompt to directly invoke 'gpg'.
echo "DO NOT RUN THIS VERSION OF GPG!!!"
echo "To run gpg, use the windows command line prompt instead of Git BASH"
echo "Note: Git itself will use the correct version of GPG when it runs, you just can't manually invoke it from Git BASH."
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment