13

With git 1.7.9, it's possible to sign a commit with the -S option. Is it possible to set it default through git config --global?

So instead of git commit -S -m 'Commit message', it would be just git commit -m 'Commit message'.

tamasd
  • 233
  • 2
  • 5

1 Answers1

12

To sign automatically all future git commits, you can define a global alias. For example, to create a global alias called "c", you would do this:

$ git config --global alias.c 'commit -s'

(note that the commit switch to sign off is lowercase "-s" and NOT uppercase "-S", as you typed in your question).

After having done this, you can start doing your commits using your newly created "c" alias. Here's an example of creating and commiting a file called "test.txt" that will be signed off by the committer:

$ vim test.txt
[edit file]
$ git add test.txt
$ git c -m 'My commit message'

You can see that the commit has the "Signed-off-by:" line if you run the "git log" command with the --pretty=fuller option:

$ git log --pretty=fuller
ricmarques
  • 1,112
  • 1
  • 13
  • 23
  • 5
    `-s` adds a "signed off by" field to the commit. `-S` actually PGP signs the commit, which was added in git 1.7.9. Also, this does not sign all commits, but only those which are made by the user directly using the `git c` command. In a rebase, when new commits are created, this will not sign off on (or PGP sign) the commits, unless you do an interactive rebase and manually commit every change. – Patrick Niedzielski Dec 06 '13 at 20:19
  • 1
    For more information on signing commits, see here: https://phreaknerd.wordpress.com/2012/02/09/signing-git-commits-with-your-gpg-key/ for instance – Patrick Niedzielski Dec 06 '13 at 20:21