git add Signed-off-by line using format.signoff not working

Update for Git 2.14.x/2.15: as I mentioned in "Git - Detect if commit is signed off programmatically", you will be able to parse a commit message trailer for Signed-off-By line.

"git interpret-trailers" has been taught a "--parse" and a few other options to make it easier for scripts to grab existing trailer lines from a commit log message.

See stefanct's answer for commit-msg client-side hook which would use git interpret-trailers.


Original answer (2013)

format.signoff is about patch (as illustrated, for instance, in this patch):

format.signoff

A boolean value which lets you enable the -s/--signoff option of format-patch by default

It has no bearing on git commit -s.

In other words, you don't have to signoff every commit, but when you are publishing them as patch for others to use (as in "git: submitting patches"), then you should sign them.

For the exact signification of Signed-of-by, see "What is the Sign Off feature in Git for?".


You can signoff by default in a project by creating a file (say "~/MYPROJECT/git-template") that contains some blank lines and the signed-off-by text like this:

Signed-off-by: Your Name <[email protected]>

Then configure git to use that as a commit template. For example:

git config commit.template ~/MYPROJECT/git-template

Make sure your project documents somewhere what signed-off-by means for the project. Here's some text you can copy into your CONTRIBUTING.md file:

All contributions (including pull requests) must agree to the Developer Certificate of Origin (DCO) version 1.1. This is exactly the same one created and used by the Linux kernel developers and posted on http://developercertificate.org/. This is a developer's certification that he or she has the right to submit the patch for inclusion into the project. Simply submitting a contribution implies this agreement, however, please include a "Signed-off-by" tag in every patch (this tag is a conventional way to confirm that you agree to the DCO).


There is now an easy way to automatically sign-off any commit that is not already signed-off by using hooks and the git-interpret-trailers command. In the upcoming version 2.15 of git the command allows to trivially check for an existing sign-off (no matter what's its value/author is) and add yours if there is non yet. As of October 2017 the required code is not in any git release yet (but in its master branch)!

Save the following as .git/hooks/prepare-commit-msg or .git/hooks/commit-msg (see here for the differences) and make it executable.

#!/bin/sh

NAME=$(git config user.name)
EMAIL=$(git config user.email)

if [ -z "$NAME" ]; then
    echo "empty git config user.name"
    exit 1
fi

if [ -z "$EMAIL" ]; then
    echo "empty git config user.email"
    exit 1
fi

git interpret-trailers --if-exists doNothing --trailer \
    "Signed-off-by: $NAME <$EMAIL>" \
    --in-place "$1"

Tags:

Git

Format

Config