Search code examples
windowsgitgnupg

Use GPG4Win Instead of Git's Internal GPG on Windows


When I run gpg --list-secret-keys --keyid-format LONG within git I get no display of keys at all. On the other hand, when I run the same command in cmd or PowerShell I get an output that looks like

enter image description here

I also added the gpg.program config in the global config file by running git config --global gpg.program "/c/Program Files (x86)/GnuPG/bin/gpg.exe". To no avail. Any idea what I could be doing wrong? As a side note, I am only using git bash and have not integrated git into windows.


Solution

  • I ended up figuring out how to use GPG4Win in Git Bash

    1. Check if GPG4Win is in your windows path variable

      • You can do this following this tutorial linked here.
      • Look for a line in the System variables PATH that looks like this enter image description here
      • If not go ahead and add it
    2. Add gpg.program into git config

      • You can do this by running git config --global gpg.program "C:/Program Files (x86)/GnuPG/bin/gpg.exe". This will make sure it is using the system-installed gpg program.

    NOTE: If you are still having issues add this line to your ~/.bashrc file and replace {Your User Directory} with your user name.

    export GNUPGHOME="/c/Users/{Your User Directory}/AppData/Roaming/gnupg"
    source ~/.bashrc # Adds the env you just added to your current session
    

    That is it you should now be able to restart git bash and view all of your keys or add keys to the Windows installed gpg program.