Search code examples
gitmacosgnupg

Git unable to sign commits


I followed the instructions on Github to setup Git signing, but I get the following error when I try to sign and commit. I searched online but I fail to the reason why --help is being included in the command to sign. I am on a Mac (M2) and Git version is 2.40.1

╭─rishabh@WKW305277K ~/Development/src  ‹feature/list-by-currency*›
╰─➤  GIT_TRACE=1 git commit -m "Initial commit"

13:02:32.970213 git.c:439               trace: built-in: git commit -m 'Initial commit'
13:02:32.991133 run-command.c:655       trace: run_command: --help --status-fd=2 -bsau 6C3C23C559AA013D352F8790061E0F7BCE5EABB8
error: cannot run --help: No such file or directory
error: gpg failed to sign the data:
(no gpg output)
fatal: failed to write commit object

To help debug the issue here are the requested information:

  1. Content of ~/.gitconfig

    ╭─rishabh@WKW305277K ~
    ╰─➤  cat ~/.gitconfig
    
    [filter "lfs"]
        required = true
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
    [user]
        name = Rishabh
        email = [email protected]
        signingkey = 6C3C23C559AA013D352F8790061E0F7BCE5EABB8
    [init]
        defaultBranch = master
    [pull]
        rebase = false
    [commit]
        template = /Users/rishabh/.gitmessage
        gpgsign = true
    [core]
        excludesfile = /Users/rishabh/.gitignore_global
    [difftool "sourcetree"]
        cmd = opendiff \"$LOCAL\" \"$REMOTE\"
        path =
    [mergetool "sourcetree"]
        cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
        trustExitCode = true
    [gpg]
        program = /opt/homebrew/opt/[email protected]/bin/gpg
    
  2. Output of gpg --status-fd=2 -bsau <key>

    ╭─rishabh@WKW305277K ~
    ╰─➤  gpg --status-fd=2 -bsau 6C3C23C559AA013D352F8790061E0F7BCE5EABB8
    
    [GNUPG:] KEY_CONSIDERED 6C3C23C559AA013D352F8790061E0F7BCE5EABB8 2
    [GNUPG:] BEGIN_SIGNING H8
    ^C
    gpg: signal Interrupt caught ... exiting
    

Solution

  • The solution required that I check the output of git config --global gpg.program and git config gpg.program on individual repositories, and then I noticed that on individual repositories I had the following:

    ╭─rishabh@WKW305277K ~/Development/src  ‹feature/list-by-currency*›
    ╰─➤  git config gpg.program
    --help
    

    which I corrected by setting the value as below and it corrected my problem.

    git config gpg.program gpg