Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GPG signing with Git and Github Desktop

Hi Github users,

You can now signed your commits on Github using at least Git 2.18.0 and Github Desktop 1.6.1.

  1. Generate a GPG key and add it to Github: https://help.github.com/articles/generating-a-new-gpg-key (if you don't want to type a passphrase on every commit, you need to press "Enter" when the console will prompt you to type a passphrase)

  2. Configure Git properly by editing the .gitconfig file using the command line git config --global --edit in a terminal, then replace YOUR_GITHUB_EMAIL, YOUR_SIGNING_KEY and GPG_BINARY_PATH with your data

[user]
  name = Xavier Foucrier
  email = YOUR_GITHUB_EMAIL
  signingkey = YOUR_SIGNING_KEY
[gpg]
  program = GPG_BINARY_PATH
[commit]
  gpgsign = true
  • YOUR_GITHUB_EMAIL: the email address used to login on Github
  • YOUR_SIGNING_KEY: the GPG key used to sign commits, should follow the GPG key ID convention, like this example: https://help.github.com/articles/telling-git-about-your-signing-key/#telling-git-about-your-gpg-key-1
  • GPG_BINARY_PATH: the GPG binary file path, depending on your Git install and your operating system:
    • Windows: gpg, gpg.exe or C:\\Program Files\\Git\\usr\\bin\\gpg.exe (can be found using where gpg in a terminal)
    • Mac or Linux: gpg or /usr/local/bin/gpg (can be found using which gpg in a terminal)
  1. Enjoy signed commits with your favorite code editor!

Note that you can temporary disable GPG signed commits by setting gpgsign = false in your .gitconfig file with git config --global commit.gpgsign false

That's all folks! πŸŽ‰

@dbrenner23
Copy link

dbrenner23 commented Jan 12, 2021

Thank you! I've been waiting a while for this! (And hadn't checked for a while...)

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Jan 13, 2021

@dbrenner23 thanks for your feedback πŸ˜‰

@EwoutH
Copy link

EwoutH commented Jan 18, 2021

Thanks a lot for this, finally signed commits from GitHub Desktop! πŸŽ‰

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Jan 18, 2021

@EwoutH, glad to help πŸ˜‰

@haneef95
Copy link

haneef95 commented Feb 1, 2021

Nice! It worked! Thanks!

Using it with multi-user setup, thanks to: https://dev.to/chakrit/multiple-identity-gitconfig-with-gpg-signing-8c0

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Feb 1, 2021

@haneef95 wow I didn't know about this!
Thanks a lot πŸ˜‰

@haneef95
Copy link

haneef95 commented Feb 1, 2021

@haneef95 wow I didn't know about this!
Thanks a lot πŸ˜‰

Welcome πŸ‘

However, Github Desktop still doesn't support multi-user AFAIK, this for Git only, which Github Desktop seems to recognise on a per repo basis. Haven't tough-tested this config yet!

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Feb 1, 2021

Good to know anyway! Thanks again πŸ˜‰

@Jaeiya
Copy link

Jaeiya commented Feb 1, 2021

It's taken me a while, but I also want to give a big Thank You for this information; I didn't want to have to stop using Github desktop for something as simple as being "verified" and now I don't πŸ‘

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Feb 28, 2021

Thanks a lot @Jaeiya πŸ˜‰

@playnox
Copy link

playnox commented May 5, 2021

Someone give this mate a medal

@xavierfoucrier
Copy link
Author

xavierfoucrier commented May 5, 2021

@playnox thx πŸ‘Œ πŸ’―

@fanaugen
Copy link

fanaugen commented Jun 2, 2021

When I set it up with these instructions, gpg-agent would prompt me for my private key’s passphrase on every commit. This Askubuntu question has a useful example of how to configure GPG agent to increase the cache time (e.g. so it only prompts once an hour or once a day): https://askubuntu.com/questions/805459/how-can-i-get-gpg-agent-to-cache-my-password

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Jun 3, 2021

@fanaugen yes, for those who decided to always type a password, there is gpg-agent cache to take into account πŸ˜‰

@rtomyj
Copy link

rtomyj commented Sep 26, 2021

Thanks, man. Helped me getting signing to work as well!

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Sep 26, 2021

@rtomyj Thanks mate πŸ˜‰

@mertowitch
Copy link

mertowitch commented Nov 14, 2021

thanks...

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Nov 18, 2021

@mertowitch You are welcome! 😎

@EwoutH
Copy link

EwoutH commented Nov 19, 2021

Maybe nice to know: Git 2.34, which was released earlier this week, supports signing with a SSH key. See for more information:

@logiky
Copy link

logiky commented Jan 27, 2022

yay, nice tip Xavier πŸ˜„, thanks!

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Jan 28, 2022

@logiky πŸ˜‰

@muhammadisa20
Copy link

muhammadisa20 commented May 16, 2022

@xavierfoucrier thanks man!

@xavierfoucrier
Copy link
Author

xavierfoucrier commented May 16, 2022

@muhammadisa20 🀘

@lunarmint
Copy link

lunarmint commented Jun 3, 2022

Been looking for how to do this, really appreciate the detailed write up!

@xavierfoucrier
Copy link
Author

xavierfoucrier commented Jul 1, 2022

@lunarmint Thanks for the feedback πŸ˜‰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment