Android Studio and Git - How do I GPG-sign my commits? Android Studio and Git - How do I GPG-sign my commits? windows windows

Android Studio and Git - How do I GPG-sign my commits?


As I mentioned in "Sign git commits with GPG", with Git 2.0:

If you want to GPG sign all your commits, you have to add the -S option all the time.
The commit.gpgsign config option allows to sign all commits automatically.

This doesn't fully work though, and is followed by issue 127802, with the following workarounds:

Created a helper script with that content:

/usr/bin/gpg –batch –no-tty "$@"

and set gpg.program to that script

Or:

Adding "no-tty" to "~/.gnupg/gpg.conf" solved the problem for me.

You might still get the error message:

Commit failed with error:gpg: problem with the agent - disabling agent usegpg: Sorry, no terminal at all requested - can't get inputerror: gpg failed to sign the datafatal: failed to write commit object

Again: bug in progress, also followed by issue 110261:

resolve it with this in addition to the previous solution (OS X):

1) brew install gnupg gnupg2 pinentry-mac

2) nano ~/.gnupg/gpg-agent.conf -> pinentry-program /usr/local/bin/pinentry-mac

3) git config -–global gpg.program gpg2


After make some test I follow this steps and it worksPlease remember to restart the Android Studio after follow this steps:

Are you tired off write the password for each commit???

nano ~/.gnupg/gpg.conf

add the following lines

use-agentno-ttydefault-key <your key id>
  • after made all the configuration and if you use MacOS. You should:

ln -s /usr/local/Cellar/libgcrypt/1.7.0_1 /usr/local/opt/libgcrypt

ln -s /usr/local/Cellar/libgpg-error/1.22 /usr/local/opt/libgpg-error

ln -s /usr/local/Cellar/libassuan/2.4.2 /usr/local/opt/libassuan

ln -s /usr/local/Cellar/pth/2.0.7 /usr/local/opt/pth

  • execute

source ~/.profile

  • make one commit using the option -S

git commit -am "my commit message" -S

  • you should get a password promp. -- put your password

Thats it!!!


If you have git for Windows installed, and selected MingGW option during setup, this is what I used to get Android Studio working with signing commits.

Programs mentioned/used with links for those who don't have them yet.

For those who wants to read the article I used to get gpg signing working in my Windows environment (The bottom half of the page starting with the git config lines are what we're more concerned with):https://jamesmckay.net/2016/02/signing-git-commits-with-gpg-on-windows/

I'll briefly walk through the process for doing the gpg portion via command line - presuming that all three programs are installed already from here on in.

Check Git setting in Android Studio

If you haven't specified where git is in Android Studio, here's where you do it in Settings:

NOTE: This can be done either in File > Project Settings for one project or File > Other Settings > Default Settings...

Version Control > Git > Path to Git Executable

Since I was using the MinGW version, it's set to:C:\Program Files\Git\mingw64\bin\git.exe

Export existing public and secret keys from MinGW version (git bash)

NOTE: Execute using MinGW prompt program

  1. gpg --export > ~/gpg-public
  2. gpg --export-secret-keys > ~/gpg-secret

NOTE: For those who don't know, ~/ is by default set to your user's home directory. (e.g. Windows 10: C:/Users/%USERNAME%)

Import exported keys into Gpg4win

NOTE: Execute using Windows Command Prompt.

  1. gpg --import < "C:/Users/%USERNAME%/gpg-public"
  2. gpg --import < "C:/Users/%USERNAME%/gpg-secret"

Replace the location with wherever your gpg-public and gpg-secret files are.

Make git use gpg from Gpg4win

As mentioned in the article. It's reposted here if you didn't open it.

NOTE: Execute using MinGW prompt program

  • git config --global gpg.program "C:/Program Files (x86)/GNU/GnuPG/gpg2.exe"

Replace the gpg.program value (keeping the gpg2.exe) above with wherever you specified the gpg4win installer to install it to.

(OPTIONAL) While you're at it, you can configure your git to auto sign your commits with a default key (git version >= 2.0 required)

  • git config --global user.name <name>
  • git config --global user.email <email>
  • git config --global user.signingkey <your-key-ID>
  • git config --global commit.gpgsign true

Replace the values in < > with your own. You can get the key ID by running gpg --list-keys and taking the ID from the line starting with pub and after the /.

Now you should be able to commit using Android Studio and see a prompt come up for the password entry.