Skip to content

Instantly share code, notes, and snippets.

@alexlopes
Created March 25, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlopes/4cd0b38ae8c6f68c42d6e98226220aca to your computer and use it in GitHub Desktop.
Save alexlopes/4cd0b38ae8c6f68c42d6e98226220aca to your computer and use it in GitHub Desktop.
Github + GPG + Custom gitconfig

Github + GPG + Custom gitconfig

Add includeIf directive into original .gitconfig

In the end of your original .gitconfig add includeIf with the directory where your .gitconfig-B will be applied:

# ref https://dzone.com/articles/how-to-use-gitconfigs-includeif
# when gitdir matchs, then use .gitconfig-B

[includeIf "gitdir:~/src/github.com/myprojects/"]
    path = ~/.gitconfig-B

Add custom options and gpg into .gitconfig-B

# ref https://dzone.com/articles/how-to-use-gitconfigs-includeif

#.gitconfig-B content:

[commit]
    gpgsign = true

[gpg]
    program = gpg

[user]
	name = <github username here>
	email = email@email.com
	signingkey = <your GPG sign key here>

Troubleshooting

If you get the following error when commit

error: gpg failed to sign the data
fatal: failed to write commit object

Kill gpg-agent and set GPG_TTY

kill -9 $(pgrep gpg-agent)
export GPG_TTY=$(tty)  

Then try to commit and push and verify

git log --show-signature -1

commit 06854fae3c93ec1ed63152c6d1176433294d9692 (HEAD -> master, origin/master, origin/HEAD)
gpg: Signature made Wed Mar 25 11:22:04 2020 -03
gpg:                using RSA key 56DA862EA1F1E684753F3504CAD550B16B996590
gpg: Good signature from "Alex Lopes (GPG for Personal Use) <lopes.alex.antonio@gmail.com>" [ultimate]
Author: alexlopes <lopes.alex.antonio@gmail.com>
Date:   Wed Mar 25 11:22:04 2020 -0300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment