11

git 2.0 has the config option commit.gpgsign which will sign all commits.

This will also apply for git stash and will ask for the password of my gpg key.

Is ther a way to automatically sign all commits, tags,... but exclude stashes?

Alexis King
  • 43,109
  • 15
  • 131
  • 205
f0i
  • 167
  • 3
  • 9
  • Does GPG not have a credential store like `ssh-agent` for SSH? –  Jun 26 '14 at 21:12
  • @Cupcake: there is `gpg-agent` which will cache the credentials, but since there normaly is some time between the last commit and stash it will (and should) ask again. – f0i Jun 27 '14 at 05:59

2 Answers2

15

This is alias territory:

git config --global alias.stashq '-c commit.gpgsign=false stash'
jthill
  • 55,082
  • 5
  • 77
  • 137
7

I like jthill's answer, just wanted to provide a slightly different option so you don't have to learn to type a new command. You can define a shell function in your .bashrc like this:

git() {
  case $1 in
    stash) set -- -c commit.gpgsign=false "$@" ;;
  esac
  command git "$@"
}

Now when you run git stash then the shell function inserts the extra arguments before calling the git binary.

Aron Griffis
  • 1,699
  • 12
  • 19
  • I upvoted this long ago, but I do want to point out that just using $1 doesn't work if you feed any options to the git command itself, for instance you can `git -C ~/other/repo push` to run push in that other repo. – jthill Jan 28 '18 at 03:36
  • @jthill Indeed, thanks, and if that's a concern then your answer is the better approach. – Aron Griffis Jan 29 '18 at 15:08