gitssh-keyssigninggit-for-windows

Why does signing commit with SSH key fail with "invalid format?" and "failed to write commit object"?


I followed GitHub's instructions for telling git about my SSH key, but when I tried to sign a commit

git commit -S

I got this error:

error: Load key 
"C:\\Users\\MyName\\AppData\\Local\\Temp/.git_signing_key_tmpC5KwFc": invalid format?

fatal: failed to write commit object

What might I be doing wrong?


Solution

  • Setup

    For Git to successfully sign the commit,

    1. Git (v2.34 or later) needs to know about your SSH key
    2. The ssh-agent needs to be running
      • eval "$(ssh-agent -s)" to start it
      • (Windows can be told to auto-start it; Mac and Linux already do.)
    3. The ssh-agent needs to have your key
      • ssh-add -L to list existing keys
      • ssh-add ~/.ssh/id_ed25519 to add your key

    Signing

    Then you should be able to sign the commit!

    git commit -S

    Automatically Signing Commits, no -S

    To automatically sign all commits, flip the switch in your settings with git config --global commit.gpgsign true

    Verifying

    More on verifying your SSH-signed commits.