Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use git commits signing in VS Code?

We are using gpg signing of commits in repository but when I try to commit changes in vscode I got this error:

gpg: cannot open tty `/dev/tty': No such device or address
error: gpg failed to sign the data

If I do "git commit" in vscode's terminal all is ok. So the problem not in git/gpg/gpg-agent I guess. Is there a way to make vscode deal with this?

like image 385
Dimanoid Avatar asked Aug 17 '17 09:08

Dimanoid


2 Answers

A pull request was recently merged and will be available in the next release of VS Code (August 2017 / 1.16). Alternatively, it is already available in insiders builds.

When available it can be enabled by adding the following to user or workspace settings (file > preferences > settings)

git.enableCommitSigning: true

Prerequisite: Having git setup to sign commits. Instructions can be found here - https://help.github.com/articles/signing-commits-using-gpg/

To set all commits for a repository to be signed by default, in Git versions 2.0.0 and above, run git config commit.gpgsign true. To set all commits in any local repository on your computer to be signed by default, run git config --global commit.gpgsign true.

To store your GPG key passphrase so you don't have to enter it every time you sign a commit, we recommend using the following tools:

For Mac users, the GPG Suite allows you to store your GPG key passphrase in the Mac OS Keychain. For Windows users, the Gpg4win integrates with other Windows tools. You can also manually configure gpg-agent to save your GPG key passphrase, but this doesn't integrate with Mac OS Keychain like ssh-agent and requires more setup.

like image 114
Llewey Avatar answered Oct 22 '22 01:10

Llewey


I meet the same problem.

enter image description here

I can't solved this problem now.

But I know Vscode needs to execute export GPG_TTY=$(tty) before executing git commit

If you can add GPG_TTY=$(tty) to the configuration file(like .bashrc) of the terminal called by vscode, you will solve the problem.

More then see: https://gist.github.com/repodevs/a18c7bb42b2ab293155aca889d447f1b

like image 39
HWZen Avatar answered Oct 22 '22 03:10

HWZen