Adding files to gitignore in Visual Studio Code

Question:

In Visual Studio Code, with git extensions installed, how do you add files or complete folders to the .gitignore file so the files do not show up in untracked changes. Specifically, using Python projects, how do you add the pycache folder and its contents to the .gitignore. I have tried right-clicking in the folder in explorer panel but the pop-menu has no git ignore menu option. Thanks in advance.

I know how to do it from the command line. Yes, just edit the .gitignore file. I was just asking how it can be done from within VS Code IDE using the git extension for VS Code.

Asked By: RedSandman

||

Answers:

So after further investigation, it is possible to add files from the pycache folder to the .gitignore file from within VS Code by using the list of untracked changed files in the ‘source control’ panel. You right-click a file and select add to .gitignore from the pop-up menu. You can’t add folders but just the individual files.

Answered By: RedSandman

This extension lets you add folders to .gitignore.

Answered By: user3185563

You can use the terminal in VS Code to do this:

  1. Create a .gitignore file
  2. echo file_name > .gitignore (This ensures that the file is written into the .gitignore file)
Answered By: Benson Thomas

You don’t need an extension, nor do you need to use the terminal. Just open the .gitignore file in an editor tab and then edit it in the editor tab. It might be helpful for you to copy the path something from the Explorer View by right clicking something and then clicking the "Copy Relative Path" context menu item. You can then paste it into the gitignore with a leading forward slash.

Answered By: starball