Edit: As of Git version 1.7.9, it is possible to sign Git commits (git commit -S
). Updating the answer slightly to reflect this.
The question title is:
Is there a way to “autosign” commits in Git with a GPG key?
Short answer: yes, but don't do it.
Addressing the typo in the question: git commit -s
does not sign the commit. Rather, from the man git-commit
page:
-s, --signoff
Add Signed-off-by line by the committer at the end of the commit log message.
This gives a log output similar to the following:
± $ git log [0:43:31]
commit 155deeaef1896c63519320c7cbaf4691355143f5
Author: User Name
Date: Mon Apr 16 00:43:27 2012 +0200
Added .gitignore
Signed-off-by: User Name
Note the "Signed-off-by: ..." bit; that was generated by the -s
flag on the git-commit
.
Quoting the release announcement email:
- "git commit" learned "-S" to GPG-sign the commit; this can be shown
with the "--show-signature" option to "git log".
So yes, you can sign commits. However, I personally urge caution with this option; automatically signing commits is next to pointless, see below:
Just a side question, maybe commits shouldn't be signed, only tags, which I never create, as I submit single commits.
That's correct. Commits are not signed; tags are. The reason for this can be found in this message by Linus Torvalds, the last paragraph of which says:
Signing
each commit is totally stupid. It just means that you automate it, and you
make the signature worth less. It also doesn't add any real value, since
the way the git DAG-chain of SHA1's work, you only ever need one
signature to make all the commits reachable from that one be effectively
covered by that one. So signing each commit is simply missing the point.
I'd encourage a browse of the linked message, which clarifies why signing commits automatically is not a good idea in a far better way than I could.
However, if you want to automatically sign a tag, you would be able to do that by wrapping the git-tag -[s|u]
in an alias; if you're going to do that, you probably want to setup your key id in ~/.gitconfig
or the project-specific .git/config
file. More information about that process can be seen in the git community book. Signing tags is infinitely more useful than signing each commit you make.