Last weekend, I discovered that the VS Code CLI has a --wait flag, or -w for short. This flag causes your shell to “Wait for the files to be closed before returning.” This means you can use VS Code as your text editor for git.

To configure VS code as your text editor for git, run the following command. If you’re on macOS, you may need to add the code command to your PATH first.

git config --global core.editor "code --wait"

The result is that git will open VS Code whenever it needs your input. When you save and close the file, you will be returned to your shell to complete the git operation. The following GIF shows an example of this.

An animated GIF shows VS Code in use as the text editor for git. The user runs 'git commit' in their shell, which opens a file in VS Code. The user types a commit message. Upon saving and closing the file, the user is returned to their shell.
When you invoke the git commit command without any arguments, git will open your text editor.

The git config core.editor commands section in the official git documentation shows how to set up a number of popular editors. The --wait flag discussed in this post is listed there.