code
code
: open files or directories in Visual Studio Code (VS Code) from the command line.
The code
command allows you to quickly open a file or a directory in VS Code without manually launching the application. Using the code
command can help streamline your workflow by enabling you to navigate your project's files and directories in the terminal and open them directly in VS Code when needed. This eliminates the need to switch between the terminal and the file explorer to locate and open files.
To use the code
command, you first need to have VS Code installed on your system. Once installed, you can open VS Code from the terminal by simply typing code
followed by the file or directory you want to open.
VS Code as the default editor for Git
To set VS Code as the default editor for Git, you can use the following command:
git config --global core.editor "code --wait"
This command sets the default editor for Git to VS Code. The --wait
flag tells Git to wait for VS Code to close before continuing execution in the terminal.
After setting VS Code as the default editor, when you run a Git command that requires you to enter a message (such as git commit
without the -m
flag), Git will open VS Code for you to enter the message. Once you save and close the file in VS Code, Git will continue with the operation.
Examples
Open the current directory in VS Code:
code .
Open a specific file in VS Code:
code README.md
Open a specific directory in VS Code:
code path/to/your/project
Hi! I'm Alex, creator of GitByBit.
And this is Gitopedia—a reference that summarizes knowledge in my Git course.
Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:
Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.