Sitemap

Configure Visual Studio Code and the Command-line For Git Integration

1 min readDec 6, 2020

VSCode’s git integration is excellent, especially when combined with the GitLens extension. VSCode has become my primary git tool.

However, as of December 2020, as far as I can tell, VSCode’s git integration relies on environment variables. So here’s a script I use to configure my git settings and start VSCode on OSX and Linux. Unfortunately, you can’t switch git identities within a VSCode instance.

This script requires your git account to be configured with an SSH public key.

To use this script and continue using git from the same shell session with the same configuration, ‘source’ it via ‘source scriptname’ or ‘. scriptname’. You can of course add this configuration to your ~/.bashrc, etc., if you haven’t already.

Other git configuration settings can be specified but I’ve found that user.name and user.email work best with github. If you’re not using github, you will need to experiment with credential.username.

#!/bin/shgit config --local user.name "github username or real name"
git config --local user.email "github primary email address"
export GIT_SSH_COMMAND="ssh -i ~/.ssh/git-private-key"
code .

--

--

Terris Linenbach
Terris Linenbach

Written by Terris Linenbach

Coder since 1980. Always seeking the Best Way. CV: https://terris.com/cv

No responses yet